mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Catch and wrap ClosedPoolError
Partially resolves #1572: "urllib3 exceptions passing through requests API". Inspired from Lukasa's 2605be11d82d42438ac7c3993810c955bde74cef.
This commit is contained in:
@@ -19,6 +19,7 @@ from .compat import urlparse, basestring
|
||||
from .utils import (DEFAULT_CA_BUNDLE_PATH, get_encoding_from_headers,
|
||||
prepend_scheme_if_needed, get_auth_from_url, urldefragauth)
|
||||
from .structures import CaseInsensitiveDict
|
||||
from .packages.urllib3.exceptions import ClosedPoolError
|
||||
from .packages.urllib3.exceptions import ConnectTimeoutError
|
||||
from .packages.urllib3.exceptions import HTTPError as _HTTPError
|
||||
from .packages.urllib3.exceptions import MaxRetryError
|
||||
@@ -421,6 +422,9 @@ class HTTPAdapter(BaseAdapter):
|
||||
|
||||
raise ConnectionError(e, request=request)
|
||||
|
||||
except ClosedPoolError as e:
|
||||
raise ConnectionError(e, request=request)
|
||||
|
||||
except _ProxyError as e:
|
||||
raise ProxyError(e)
|
||||
|
||||
|
||||
@@ -1655,6 +1655,16 @@ def test_urllib3_retries():
|
||||
with pytest.raises(RetryError):
|
||||
s.get(httpbin('status/500'))
|
||||
|
||||
|
||||
def test_urllib3_pool_connection_closed():
|
||||
s = requests.Session()
|
||||
s.mount('http://', HTTPAdapter(pool_connections=0, pool_maxsize=0))
|
||||
|
||||
try:
|
||||
s.get(httpbin('status/200'))
|
||||
except ConnectionError as e:
|
||||
assert u"HTTPConnectionPool(host='httpbin.org', port=80): Pool is closed." in str(e.message)
|
||||
|
||||
def test_vendor_aliases():
|
||||
from requests.packages import urllib3
|
||||
from requests.packages import chardet
|
||||
|
||||
Reference in New Issue
Block a user