From: Kenneth Reitz Date: Sat, 12 Nov 2011 18:01:05 +0000 (-0800) Subject: Timeouts for urllib3 X-Git-Tag: v0.8.0~32 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=7c206c74ba270bdfa2e748c33e4c6c89deea517b;p=services%2Fpython-requests.git Timeouts for urllib3 --- diff --git a/requests/models.py b/requests/models.py index 7825956..64641c5 100644 --- a/requests/models.py +++ b/requests/models.py @@ -20,6 +20,8 @@ from .hooks import dispatch_hook from .structures import CaseInsensitiveDict from .status_codes import codes from .packages.urllib3.exceptions import MaxRetryError +from .packages.urllib3.exceptions import SSLError as _SSLError +from .packages.urllib3.exceptions import HTTPError as _HTTPError from .packages.urllib3 import connectionpool, poolmanager from .exceptions import ( Timeout, URLRequired, TooManyRedirects, HTTPError, ConnectionError) @@ -405,15 +407,21 @@ class Request(object): assert_same_host=False, preload_content=prefetch, decode_content=False, - retries=self.config.get('max_retries', 0) + retries=self.config.get('max_retries', 0), + timeout=self.timeout, ) + except MaxRetryError, e: if not self.config.get('safe_mode', False): raise ConnectionError(e) else: r = None + except (_SSLError, _HTTPError), e: + if not self.config.get('safe_mode', False): + raise Timeout('Request timed out.') + self._build_response(r) # Response manipulation hook.