diff --git a/requests/models.py b/requests/models.py index 41108cf3..099f1c66 100644 --- a/requests/models.py +++ b/requests/models.py @@ -296,15 +296,15 @@ class Request(object): if self.cookiejar is not None: self.cookiejar.extract_cookies(resp, req) - except urllib2.HTTPError, why: + except (urllib2.HTTPError, urllib2.URLError), why: + if hasattr(why, 'reason'): + if isinstance(why.reason, socket.timeout): + why = Timeout(why) + self._build_response(why) if not self.redirect: self.response.error = why - # TODO: Support urllib connection refused errors - - except urllib2.URLError, error: - raise Timeout if isinstance(error.reason, socket.timeout) else error else: self._build_response(resp) self.response.ok = True diff --git a/test_requests.py b/test_requests.py index aa2577dd..848297e4 100755 --- a/test_requests.py +++ b/test_requests.py @@ -246,8 +246,13 @@ class RequestsTestSuite(unittest.TestCase): def test_settings(self): + + def test(): + r = requests.get(httpbin('')) + r.raise_for_status() + with requests.settings(timeout=0.0000001): - self.assertRaises(requests.Timeout, requests.get, httpbin('')) + self.assertRaises(requests.Timeout, test) with requests.settings(timeout=100): requests.get(httpbin(''))