print error message prefixed by Youtube for more reliability

This commit is contained in:
LecygneNoir 2018-03-07 14:15:24 +01:00
parent 729101b468
commit 1ecc9cab25

View file

@ -99,31 +99,31 @@ def resumable_upload(request):
retry = 0 retry = 0
while response is None: while response is None:
try: try:
print 'Uploading file...' print 'Youtube : Uploading file...'
status, response = request.next_chunk() status, response = request.next_chunk()
if response is not None: if response is not None:
if 'id' in response: if 'id' in response:
print 'Video id "%s" was successfully uploaded.' % response['id'] print 'Youtube : Video id "%s" was successfully uploaded.' % response['id']
else: else:
exit('The upload failed with an unexpected response: %s' % response) exit('Youtube : The upload failed with an unexpected response: %s' % response)
except HttpError, e: except HttpError, e:
if e.resp.status in RETRIABLE_STATUS_CODES: if e.resp.status in RETRIABLE_STATUS_CODES:
error = 'A retriable HTTP error %d occurred:\n%s' % (e.resp.status, error = 'Youtube : A retriable HTTP error %d occurred:\n%s' % (e.resp.status,
e.content) e.content)
else: else:
raise raise
except RETRIABLE_EXCEPTIONS, e: except RETRIABLE_EXCEPTIONS, e:
error = 'A retriable error occurred: %s' % e error = 'Youtube : A retriable error occurred: %s' % e
if error is not None: if error is not None:
print error print error
retry += 1 retry += 1
if retry > MAX_RETRIES: if retry > MAX_RETRIES:
exit('No longer attempting to retry.') exit('Youtube : No longer attempting to retry.')
max_sleep = 2 ** retry max_sleep = 2 ** retry
sleep_seconds = random.random() * max_sleep sleep_seconds = random.random() * max_sleep
print 'Sleeping %f seconds and then retrying...' % sleep_seconds print 'Youtube : Sleeping %f seconds and then retrying...' % sleep_seconds
time.sleep(sleep_seconds) time.sleep(sleep_seconds)
@ -132,4 +132,4 @@ def run(options):
try: try:
initialize_upload(youtube, options) initialize_upload(youtube, options)
except HttpError, e: except HttpError, e:
print 'An HTTP error %d occurred:\n%s' % (e.resp.status, e.content) print 'Youtube : An HTTP error %d occurred:\n%s' % (e.resp.status, e.content)