fix: Adding ConnectionError to retry mechanism (#822)
This commit fixes issue googleapis#558
Co-authored-by: Bu Sun Kim <8822365+busunkim96@users.noreply.github.com>
diff --git a/googleapiclient/http.py b/googleapiclient/http.py
index cf9a509..cd2775a 100644
--- a/googleapiclient/http.py
+++ b/googleapiclient/http.py
@@ -81,6 +81,11 @@
_LEGACY_BATCH_URI = "https://www.googleapis.com/batch"
+if six.PY2:
+ # That's a builtin python3 exception, nonexistent in python2.
+ # Defined to None to avoid NameError while trying to catch it
+ ConnectionError = None
+
def _should_retry_response(resp_status, content):
"""Determines whether a response should be retried.
@@ -177,6 +182,10 @@
# It's important that this be before socket.error as it's a subclass
# socket.timeout has no errorcode
exception = socket_timeout
+ except ConnectionError as connection_error:
+ # Needs to be before socket.error as it's a subclass of
+ # OSError (socket.error)
+ exception = connection_error
except socket.error as socket_error:
# errno's contents differ by platform, so we have to match by name.
if socket.errno.errorcode.get(socket_error.errno) not in {