Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions googleapiclient/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,14 @@ def _retry_request(http, num_retries, req_type, sleep, rand, uri, method, *args,
# Retry on SSL errors and socket timeout errors.
except _ssl_SSLError as ssl_error:
exception = ssl_error
except socket.timeout as socket_timeout:
# It's important that this be before socket.error as it's a subclass
# socket.timeout has no errorcode
exception = socket_timeout
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 (
'WSAETIMEDOUT', 'ETIMEDOUT', 'EPIPE', 'ECONNABORTED', ):
if socket.errno.errorcode.get(socket_error.errno) not in {
'WSAETIMEDOUT', 'ETIMEDOUT', 'EPIPE', 'ECONNABORTED'}:
raise
exception = socket_error

Expand Down
18 changes: 10 additions & 8 deletions tests/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,24 +125,26 @@ def request(self, *args, **kwargs):
return httplib2.Response(self.success_json), self.success_data
else:
self.num_errors -= 1
if self.num_errors == 1:
if self.num_errors == 1: # initial == 2
raise ssl.SSLError()
else:
if PY3:
ex = TimeoutError()
else:
ex = socket.error()
else: # initial != 2
if self.num_errors == 2:
#first try a broken pipe error (#218)
# first try a broken pipe error (#218)
ex = socket.error()
ex.errno = socket.errno.EPIPE
else:
# Initialize the timeout error code to the platform's error code.
try:
# For Windows:
ex = socket.error()
ex.errno = socket.errno.WSAETIMEDOUT
except AttributeError:
# For Linux/Mac:
ex.errno = socket.errno.ETIMEDOUT
if PY3:
ex = socket.timeout()
else:
ex = socket.error()
ex.errno = socket.errno.ETIMEDOUT
# Now raise the correct error.
raise ex

Expand Down