Catch and wrap ClosedPoolError

Partially resolves #1572: "urllib3 exceptions passing through requests
API".

Inspired from Lukasa's 2605be11d82d42438ac7c3993810c955bde74cef.
This commit is contained in:
Susan Tan
2015-07-17 01:18:02 -07:00
parent 0be38a0c37
commit 5ec7576f23
2 changed files with 14 additions and 0 deletions
+4
View File
@@ -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)
+10
View File
@@ -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