diff --git a/requests/adapters.py b/requests/adapters.py index 4f2b23cf..fe9f5338 100644 --- a/requests/adapters.py +++ b/requests/adapters.py @@ -434,6 +434,9 @@ class HTTPAdapter(BaseAdapter): if isinstance(e.reason, ResponseError): raise RetryError(e, request=request) + if isinstance(e.reason, _ProxyError): + raise ProxyError(e, request=request) + raise ConnectionError(e, request=request) except ClosedPoolError as e: diff --git a/tests/test_requests.py b/tests/test_requests.py index 01811b8a..282a6679 100755 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -21,7 +21,8 @@ from requests.compat import ( from requests.cookies import cookiejar_from_dict, morsel_to_cookie from requests.exceptions import ( ConnectionError, ConnectTimeout, InvalidSchema, InvalidURL, - MissingSchema, ReadTimeout, Timeout, RetryError, TooManyRedirects) + MissingSchema, ReadTimeout, Timeout, RetryError, TooManyRedirects, + ProxyError) from requests.models import PreparedRequest from requests.structures import CaseInsensitiveDict from requests.sessions import SessionRedirectMixin @@ -358,6 +359,11 @@ class TestRequests: with pytest.raises(exception): requests.get(url, timeout=1) + def test_proxy_error(self): + # any proxy related error (address resolution, no route to host, etc) should result in a ProxyError + with pytest.raises(ProxyError): + requests.get('http://localhost:1', proxies={'http': 'non-resolvable-address'}) + def test_basicauth_with_netrc(self, httpbin): auth = ('user', 'pass') wrong_auth = ('wronguser', 'wrongpass')