From: schlamar Date: Mon, 10 Mar 2014 06:54:22 +0000 (+0100) Subject: Catch possible exceptions while consuming content of redirect responses. X-Git-Tag: v2.3.0~2^2~2^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c2a1f28a2ebd9448be7b4c8f9207d16c894717c3;p=services%2Fpython-requests.git Catch possible exceptions while consuming content of redirect responses. --- diff --git a/requests/sessions.py b/requests/sessions.py index 6b21b5d..fe8d7e2 100644 --- a/requests/sessions.py +++ b/requests/sessions.py @@ -19,7 +19,8 @@ from .cookies import ( from .models import Request, PreparedRequest, DEFAULT_REDIRECT_LIMIT from .hooks import default_hooks, dispatch_hook from .utils import to_key_val_list, default_headers, to_native_string -from .exceptions import TooManyRedirects, InvalidSchema +from .exceptions import ( + TooManyRedirects, InvalidSchema, ChunkedEncodingError, ContentDecodingError) from .structures import CaseInsensitiveDict from .adapters import HTTPAdapter @@ -94,7 +95,10 @@ class SessionRedirectMixin(object): while resp.is_redirect: prepared_request = req.copy() - resp.content # Consume socket so it can be released + try: + resp.content # Consume socket so it can be released + except (ChunkedEncodingError, ContentDecodingError, RuntimeError): + resp.raw.read(decode_content=False) if i >= self.max_redirects: raise TooManyRedirects('Exceeded %s redirects.' % self.max_redirects)