@@ -1232,7 +1232,42 @@ def gather(self, *responses: Response, max_fetch: int | None = None) -> None:
1232
1232
self ._orphaned .remove (low_resp )
1233
1233
1234
1234
if low_resp is None :
1235
- low_resp = self .poolmanager .get_response ()
1235
+ try :
1236
+ low_resp = self .poolmanager .get_response ()
1237
+ except (ProtocolError , OSError ) as err :
1238
+ raise ConnectionError (err )
1239
+
1240
+ except MaxRetryError as e :
1241
+ if isinstance (e .reason , ConnectTimeoutError ):
1242
+ # TODO: Remove this in 3.0.0: see #2811
1243
+ if not isinstance (e .reason , NewConnectionError ):
1244
+ raise ConnectTimeout (e )
1245
+
1246
+ if isinstance (e .reason , ResponseError ):
1247
+ raise RetryError (e )
1248
+
1249
+ if isinstance (e .reason , _ProxyError ):
1250
+ raise ProxyError (e )
1251
+
1252
+ if isinstance (e .reason , _SSLError ):
1253
+ # This branch is for urllib3 v1.22 and later.
1254
+ raise SSLError (e )
1255
+
1256
+ raise ConnectionError (e )
1257
+
1258
+ except _ProxyError as e :
1259
+ raise ProxyError (e )
1260
+
1261
+ except (_SSLError , _HTTPError ) as e :
1262
+ if isinstance (e , _SSLError ):
1263
+ # This branch is for urllib3 versions earlier than v1.22
1264
+ raise SSLError (e )
1265
+ elif isinstance (e , ReadTimeoutError ):
1266
+ raise ReadTimeout (e )
1267
+ elif isinstance (e , _InvalidHeader ):
1268
+ raise InvalidHeader (e )
1269
+ else :
1270
+ raise
1236
1271
1237
1272
if low_resp is None :
1238
1273
break
@@ -1278,6 +1313,40 @@ def gather(self, *responses: Response, max_fetch: int | None = None) -> None:
1278
1313
)
1279
1314
except ValueError :
1280
1315
low_resp = None
1316
+ except (ProtocolError , OSError ) as err :
1317
+ raise ConnectionError (err )
1318
+
1319
+ except MaxRetryError as e :
1320
+ if isinstance (e .reason , ConnectTimeoutError ):
1321
+ # TODO: Remove this in 3.0.0: see #2811
1322
+ if not isinstance (e .reason , NewConnectionError ):
1323
+ raise ConnectTimeout (e )
1324
+
1325
+ if isinstance (e .reason , ResponseError ):
1326
+ raise RetryError (e )
1327
+
1328
+ if isinstance (e .reason , _ProxyError ):
1329
+ raise ProxyError (e )
1330
+
1331
+ if isinstance (e .reason , _SSLError ):
1332
+ # This branch is for urllib3 v1.22 and later.
1333
+ raise SSLError (e )
1334
+
1335
+ raise ConnectionError (e )
1336
+
1337
+ except _ProxyError as e :
1338
+ raise ProxyError (e )
1339
+
1340
+ except (_SSLError , _HTTPError ) as e :
1341
+ if isinstance (e , _SSLError ):
1342
+ # This branch is for urllib3 versions earlier than v1.22
1343
+ raise SSLError (e )
1344
+ elif isinstance (e , ReadTimeoutError ):
1345
+ raise ReadTimeout (e )
1346
+ elif isinstance (e , _InvalidHeader ):
1347
+ raise InvalidHeader (e )
1348
+ else :
1349
+ raise
1281
1350
1282
1351
if low_resp is None :
1283
1352
raise MultiplexingError (
@@ -2257,7 +2326,42 @@ async def gather(
2257
2326
self ._orphaned .remove (low_resp )
2258
2327
2259
2328
if low_resp is None :
2260
- low_resp = await self .poolmanager .get_response ()
2329
+ try :
2330
+ low_resp = await self .poolmanager .get_response ()
2331
+ except (ProtocolError , OSError ) as err :
2332
+ raise ConnectionError (err )
2333
+
2334
+ except MaxRetryError as e :
2335
+ if isinstance (e .reason , ConnectTimeoutError ):
2336
+ # TODO: Remove this in 3.0.0: see #2811
2337
+ if not isinstance (e .reason , NewConnectionError ):
2338
+ raise ConnectTimeout (e )
2339
+
2340
+ if isinstance (e .reason , ResponseError ):
2341
+ raise RetryError (e )
2342
+
2343
+ if isinstance (e .reason , _ProxyError ):
2344
+ raise ProxyError (e )
2345
+
2346
+ if isinstance (e .reason , _SSLError ):
2347
+ # This branch is for urllib3 v1.22 and later.
2348
+ raise SSLError (e )
2349
+
2350
+ raise ConnectionError (e )
2351
+
2352
+ except _ProxyError as e :
2353
+ raise ProxyError (e )
2354
+
2355
+ except (_SSLError , _HTTPError ) as e :
2356
+ if isinstance (e , _SSLError ):
2357
+ # This branch is for urllib3 versions earlier than v1.22
2358
+ raise SSLError (e )
2359
+ elif isinstance (e , ReadTimeoutError ):
2360
+ raise ReadTimeout (e )
2361
+ elif isinstance (e , _InvalidHeader ):
2362
+ raise InvalidHeader (e )
2363
+ else :
2364
+ raise
2261
2365
2262
2366
if low_resp is None :
2263
2367
break
@@ -2303,6 +2407,40 @@ async def gather(
2303
2407
)
2304
2408
except ValueError :
2305
2409
low_resp = None
2410
+ except (ProtocolError , OSError ) as err :
2411
+ raise ConnectionError (err )
2412
+
2413
+ except MaxRetryError as e :
2414
+ if isinstance (e .reason , ConnectTimeoutError ):
2415
+ # TODO: Remove this in 3.0.0: see #2811
2416
+ if not isinstance (e .reason , NewConnectionError ):
2417
+ raise ConnectTimeout (e )
2418
+
2419
+ if isinstance (e .reason , ResponseError ):
2420
+ raise RetryError (e )
2421
+
2422
+ if isinstance (e .reason , _ProxyError ):
2423
+ raise ProxyError (e )
2424
+
2425
+ if isinstance (e .reason , _SSLError ):
2426
+ # This branch is for urllib3 v1.22 and later.
2427
+ raise SSLError (e )
2428
+
2429
+ raise ConnectionError (e )
2430
+
2431
+ except _ProxyError as e :
2432
+ raise ProxyError (e )
2433
+
2434
+ except (_SSLError , _HTTPError ) as e :
2435
+ if isinstance (e , _SSLError ):
2436
+ # This branch is for urllib3 versions earlier than v1.22
2437
+ raise SSLError (e )
2438
+ elif isinstance (e , ReadTimeoutError ):
2439
+ raise ReadTimeout (e )
2440
+ elif isinstance (e , _InvalidHeader ):
2441
+ raise InvalidHeader (e )
2442
+ else :
2443
+ raise
2306
2444
2307
2445
if low_resp is None :
2308
2446
raise MultiplexingError (
0 commit comments