summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Reitz <me@kennethreitz.org>2014-09-04 11:39:41 -0700
committerKenneth Reitz <me@kennethreitz.org>2014-09-04 11:39:41 -0700
commit1324ca1a0f6e4fc48a7edf5dd1766d528e557520 (patch)
tree3bf930ebd316bcfd89a0373befb19f3a67e32242
parent209a871b638f85e2c61966f82e547377ed4260d9 (diff)
parent9354855648cedbec3a91a9391e067f56e8414814 (diff)
downloadpython-requests-1324ca1a0f6e4fc48a7edf5dd1766d528e557520.tar.gz
Merge pull request #2193 from sigmavirus24/bug/2192
Capture and re-raise urllib3 ProtocolError
-rw-r--r--requests/adapters.py5
-rwxr-xr-xtest_requests.py8
2 files changed, 11 insertions, 2 deletions
diff --git a/requests/adapters.py b/requests/adapters.py
index ed7a9072..d17d9e69 100644
--- a/requests/adapters.py
+++ b/requests/adapters.py
@@ -23,6 +23,7 @@ from .packages.urllib3.exceptions import ConnectTimeoutError
from .packages.urllib3.exceptions import HTTPError as _HTTPError
from .packages.urllib3.exceptions import MaxRetryError
from .packages.urllib3.exceptions import ProxyError as _ProxyError
+from .packages.urllib3.exceptions import ProtocolError
from .packages.urllib3.exceptions import ReadTimeoutError
from .packages.urllib3.exceptions import SSLError as _SSLError
from .cookies import extract_cookies_to_jar
@@ -402,8 +403,8 @@ class HTTPAdapter(BaseAdapter):
# All is well, return the connection to the pool.
conn._put_conn(low_conn)
- except socket.error as sockerr:
- raise ConnectionError(sockerr, request=request)
+ except (ProtocolError, socket.error) as err:
+ raise ConnectionError(err, request=request)
except MaxRetryError as e:
if isinstance(e.reason, ConnectTimeoutError):
diff --git a/test_requests.py b/test_requests.py
index 716c0dcf..2ff61248 100755
--- a/test_requests.py
+++ b/test_requests.py
@@ -286,6 +286,14 @@ class RequestsTestCase(unittest.TestCase):
r = s.get(url)
assert r.status_code == 200
+ def test_connection_error(self):
+ """Connecting to an unknown domain should raise a ConnectionError"""
+ with pytest.raises(ConnectionError):
+ requests.get("http://fooobarbangbazbing.httpbin.org")
+
+ with pytest.raises(ConnectionError):
+ requests.get("http://httpbin.org:1")
+
def test_basicauth_with_netrc(self):
auth = ('user', 'pass')
wrong_auth = ('wronguser', 'wrongpass')