Merge pull request #3059 from alexanderad/proxy-connection-errors

Raise a ProxyError for proxy related connection issues
This commit is contained in:
2016-04-06 15:01:25 -04:00
2 changed files with 10 additions and 1 deletions
+3
View File
@@ -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:
+7 -1
View File
@@ -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')