media = self.chunked_upload_finalize(media_id, **kwargs)
if wait_for_async_finalize and hasattr(media, 'processing_info'):
- while media.processing_info['state'] in ('pending', 'in_progress'):
+ while (
+ media.processing_info['state'] in (
+ 'pending', 'in_progress'
+ ) and 'error' not in media.processing_info
+ ):
time.sleep(media.processing_info['check_after_secs'])
media = self.get_media_upload_status(media.media_id, **kwargs)