Browse Source

Merge pull request #216 from vobruba-martin/retry-http-5xx-errors

Retry HTTP 5xx errors and avoid raising UnicodeEncodeError
Arnau Sanchez 6 years ago
parent
commit
da824ffef6
2 changed files with 6 additions and 0 deletions
  1. 5 0
      youtube_upload/lib.py
  2. 1 0
      youtube_upload/upload_video.py

+ 5 - 0
youtube_upload/lib.py

@@ -7,6 +7,8 @@ import time
 import signal
 from contextlib import contextmanager
 
+import googleapiclient.errors
+
 @contextmanager
 def default_sigint():
     original_sigint_handler = signal.getsignal(signal.SIGINT)
@@ -72,6 +74,9 @@ def retriable_exceptions(fun, retriable_exceptions, max_retries=None):
             retry += 1
             if type(exc) not in retriable_exceptions:
                 raise exc
+            # we want to retry 5xx errors only
+            elif type(exc) == googleapiclient.errors.HttpError and exc.resp.status < 500:
+                raise exc
             elif max_retries is not None and retry > max_retries:
                 debug("[Retryable errors] Retry limit reached")
                 raise exc

+ 1 - 0
youtube_upload/upload_video.py

@@ -16,6 +16,7 @@ RETRIABLE_EXCEPTIONS = [
     httplib.IncompleteRead, httplib.ImproperConnectionState,
     httplib.CannotSendRequest, httplib.CannotSendHeader,
     httplib.ResponseNotReady, httplib.BadStatusLine,
+    googleapiclient.errors.HttpError,
 ]
 
 def _upload_to_request(request, progress_callback):