for attempt in range(3): try: download_image(image_id) break except NCSW10301: refresh_metadata() time.sleep(30 * (attempt + 1))