diff --git a/requests/adapters.py b/requests/adapters.py index 841cbbfe..cf468608 100644 --- a/requests/adapters.py +++ b/requests/adapters.py @@ -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) diff --git a/test_requests.py b/test_requests.py index 5f4f472a..6b43a92c 100755 --- a/test_requests.py +++ b/test_requests.py @@ -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