diff options
author | Kenneth Reitz <me@kennethreitz.org> | 2014-10-05 12:48:40 -0400 |
---|---|---|
committer | Kenneth Reitz <me@kennethreitz.org> | 2014-10-05 12:48:40 -0400 |
commit | 65cdccb70f79443b868853c5543e65b2610452f7 (patch) | |
tree | 67751e9def3ac84945252364e056184513c3e079 | |
parent | 1e79cf6a47edc47968dc14221d8c8765ab8341c8 (diff) | |
parent | 64ba451049c614eb14d336c2e7989ffaa81b2bb5 (diff) | |
download | python-requests-65cdccb70f79443b868853c5543e65b2610452f7.tar.gz |
Merge pull request #2241 from tijko/master
raise RuntimeError when a single streamed request calls *iter methods th...
-rw-r--r-- | requests/exceptions.py | 3 | ||||
-rw-r--r-- | requests/models.py | 7 |
2 files changed, 8 insertions, 2 deletions
diff --git a/requests/exceptions.py b/requests/exceptions.py index d8f05f08..34c7a0db 100644 --- a/requests/exceptions.py +++ b/requests/exceptions.py @@ -89,3 +89,6 @@ class ChunkedEncodingError(RequestException): class ContentDecodingError(RequestException, BaseHTTPError): """Failed to decode response content""" + +class StreamConsumedError(RequestException, TypeError): + """The content for this response was already consumed""" diff --git a/requests/models.py b/requests/models.py index 40a2a0cb..245521dc 100644 --- a/requests/models.py +++ b/requests/models.py @@ -22,8 +22,9 @@ from .packages.urllib3.util import parse_url from .packages.urllib3.exceptions import ( DecodeError, ReadTimeoutError, ProtocolError) from .exceptions import ( - HTTPError, RequestException, MissingSchema, InvalidURL, - ChunkedEncodingError, ContentDecodingError, ConnectionError) + HTTPError, RequestException, MissingSchema, InvalidURL, + ChunkedEncodingError, ContentDecodingError, ConnectionError, + StreamConsumedError) from .utils import ( guess_filename, get_auth_from_url, requote_uri, stream_decode_response_unicode, to_key_val_list, parse_header_links, @@ -667,6 +668,8 @@ class Response(object): self._content_consumed = True + if self._content_consumed and isinstance(self._content, bool): + raise StreamConsumedError() # simulate reading small chunks of the content reused_chunks = iter_slices(self._content, chunk_size) |