Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

raise RuntimeError when a single streamed request calls *iter methods th... #2241

Merged
merged 5 commits into from
Oct 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions requests/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
7 changes: 5 additions & 2 deletions requests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
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,
Expand Down Expand Up @@ -655,6 +656,8 @@ def generate():

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)

Expand Down