Skip to content

Commit b7b9986

Browse files
authored
fix: replace deprecated socket.error with OSError (#1161)
Fixes #1148 🦕
1 parent ae9cd99 commit b7b9986

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

googleapiclient/http.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,14 +178,13 @@ def _retry_request(
178178
except _ssl_SSLError as ssl_error:
179179
exception = ssl_error
180180
except socket.timeout as socket_timeout:
181-
# It's important that this be before socket.error as it's a subclass
181+
# Needs to be before socket.error as it's a subclass of OSError
182182
# socket.timeout has no errorcode
183183
exception = socket_timeout
184184
except ConnectionError as connection_error:
185-
# Needs to be before socket.error as it's a subclass of
186-
# OSError (socket.error)
185+
# Needs to be before socket.error as it's a subclass of OSError
187186
exception = connection_error
188-
except socket.error as socket_error:
187+
except OSError as socket_error:
189188
# errno's contents differ by platform, so we have to match by name.
190189
# Some of these same errors may have been caught above, e.g. ECONNRESET *should* be
191190
# raised as a ConnectionError, but some libraries will raise it as a socket.error

tests/test_http.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,22 +137,22 @@ def request(self, *args, **kwargs):
137137
elif self.num_errors == 4:
138138
ex = httplib2.ServerNotFoundError()
139139
elif self.num_errors == 3:
140-
ex = socket.error()
140+
ex = OSError()
141141
ex.errno = socket.errno.EPIPE
142142
elif self.num_errors == 2:
143143
ex = ssl.SSLError()
144144
else:
145145
# Initialize the timeout error code to the platform's error code.
146146
try:
147147
# For Windows:
148-
ex = socket.error()
148+
ex = OSError()
149149
ex.errno = socket.errno.WSAETIMEDOUT
150150
except AttributeError:
151151
# For Linux/Mac:
152152
if PY3:
153153
ex = socket.timeout()
154154
else:
155-
ex = socket.error()
155+
ex = OSError()
156156
ex.errno = socket.errno.ETIMEDOUT
157157

158158
self.num_errors -= 1
@@ -170,7 +170,7 @@ def request(self, *args, **kwargs):
170170
return httplib2.Response(self.success_json), self.success_data
171171
else:
172172
self.num_errors -= 1
173-
ex = socket.error()
173+
ex = OSError()
174174
# set errno to a non-retriable value
175175
try:
176176
# For Windows:
@@ -943,7 +943,7 @@ def test_no_retry_connection_errors(self):
943943
)
944944
request._sleep = lambda _x: 0 # do nothing
945945
request._rand = lambda: 10
946-
with self.assertRaises(socket.error):
946+
with self.assertRaises(OSError):
947947
response = request.execute(num_retries=3)
948948

949949
def test_retry_connection_errors_non_resumable(self):

0 commit comments

Comments
 (0)