@@ -278,6 +278,23 @@ def _get_timeout(self, timeout):
278
278
# can be removed later
279
279
return Timeout .from_float (timeout )
280
280
281
+ def _raise_timeout (self , err , url , timeout_value ):
282
+ """Is the error actually a timeout? Will raise a ReadTimeout or pass"""
283
+
284
+ if isinstance (err , SocketTimeout ):
285
+ raise ReadTimeoutError (self , url , "Read timed out. (read timeout=%s)" % timeout_value )
286
+
287
+ # See the above comment about EAGAIN in Python 3. In Python 2 we have
288
+ # to specifically catch it and throw the timeout error
289
+ if hasattr (err , 'errno' ) and err .errno in _blocking_errnos :
290
+ raise ReadTimeoutError (self , url , "Read timed out. (read timeout=%s)" % timeout_value )
291
+
292
+ # Catch possible read timeouts thrown as SSL errors. If not the
293
+ # case, rethrow the original. We need to do this because of:
294
+ # http://bugs.python.org/issue10272
295
+ if 'timed out' in str (err ) or 'did not complete (read)' in str (err ): # Python 2.6
296
+ raise ReadTimeoutError (self , url , "Read timed out. (read timeout=%s)" % timeout_value )
297
+
281
298
def _make_request (self , conn , method , url , timeout = _Default ,
282
299
** httplib_request_kw ):
283
300
"""
@@ -301,7 +318,12 @@ def _make_request(self, conn, method, url, timeout=_Default,
301
318
conn .timeout = timeout_obj .connect_timeout
302
319
303
320
# Trigger any extra validation we need to do.
304
- self ._validate_conn (conn )
321
+ try :
322
+ self ._validate_conn (conn )
323
+ except (SocketTimeout , BaseSSLError ) as e :
324
+ # Py2 raises this as a BaseSSLError, Py3 raises it as socket timeout.
325
+ self ._raise_timeout (err = e , url = url , timeout_value = conn .timeout )
326
+ raise
305
327
306
328
# conn.request() calls httplib.*.request, not the method in
307
329
# urllib3.request. It also calls makefile (recv) on the socket.
@@ -331,28 +353,8 @@ def _make_request(self, conn, method, url, timeout=_Default,
331
353
httplib_response = conn .getresponse (buffering = True )
332
354
except TypeError : # Python 2.6 and older
333
355
httplib_response = conn .getresponse ()
334
- except SocketTimeout :
335
- raise ReadTimeoutError (
336
- self , url , "Read timed out. (read timeout=%s)" % read_timeout )
337
-
338
- except BaseSSLError as e :
339
- # Catch possible read timeouts thrown as SSL errors. If not the
340
- # case, rethrow the original. We need to do this because of:
341
- # http://bugs.python.org/issue10272
342
- if 'timed out' in str (e ) or \
343
- 'did not complete (read)' in str (e ): # Python 2.6
344
- raise ReadTimeoutError (
345
- self , url , "Read timed out. (read timeout=%s)" % read_timeout )
346
-
347
- raise
348
-
349
- except SocketError as e : # Platform-specific: Python 2
350
- # See the above comment about EAGAIN in Python 3. In Python 2 we
351
- # have to specifically catch it and throw the timeout error
352
- if e .errno in _blocking_errnos :
353
- raise ReadTimeoutError (
354
- self , url , "Read timed out. (read timeout=%s)" % read_timeout )
355
-
356
+ except (SocketTimeout , BaseSSLError , SocketError ) as e :
357
+ self ._raise_timeout (err = e , url = url , timeout_value = read_timeout )
356
358
raise
357
359
358
360
# AppEngine doesn't have a version attr.
0 commit comments