diff --git a/requests/exceptions.py b/requests/exceptions.py index bc42b5ff..7caf4db2 100644 --- a/requests/exceptions.py +++ b/requests/exceptions.py @@ -61,3 +61,7 @@ class InvalidURL(RequestException, ValueError): class ChunkedEncodingError(RequestException): """The server declared chunked encoding but sent an invalid chunk.""" + + +class ContentDecodingError(RequestException): + """Failed to decode response content""" diff --git a/requests/models.py b/requests/models.py index e2a03d05..1fdf43ab 100644 --- a/requests/models.py +++ b/requests/models.py @@ -20,9 +20,10 @@ from .cookies import cookiejar_from_dict, get_cookie_header from .packages.urllib3.fields import RequestField from .packages.urllib3.filepost import encode_multipart_formdata from .packages.urllib3.util import parse_url +from .packages.urllib3.exceptions import DecodeError from .exceptions import ( HTTPError, RequestException, MissingSchema, InvalidURL, - ChunkedEncodingError) + ChunkedEncodingError, ContentDecodingError) from .utils import ( guess_filename, get_auth_from_url, requote_uri, stream_decode_response_unicode, to_key_val_list, parse_header_links, @@ -616,6 +617,8 @@ class Response(object): yield chunk except IncompleteRead as e: raise ChunkedEncodingError(e) + except DecodeError as e: + raise ContentDecodingError(e) except AttributeError: # Standard file-like object. while True: