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

Conversation

@tijko
Copy link
Contributor

commented Sep 22, 2014

In response to issue #2240, add a check to see if the content was "consumed"

@Lukasa

This comment has been minimized.

Copy link
Member

commented Sep 22, 2014

Let's have a subclass of RequestException. My proposed name is BodyConsumedError: @sigmavirus24, do you have a better one?

if self._content_consumed and isinstance(self._content, bool):
raise RuntimeError(
'The content for this response was already consumed')
else:

This comment has been minimized.

Copy link
@Lukasa

Lukasa Sep 22, 2014

Member

No need for the else or the subsequent indentation, we won't get this far if we raise anyway.

@kevinburke

This comment has been minimized.

Copy link
Contributor

commented Sep 22, 2014

EOFError?

@sigmavirus24

This comment has been minimized.

Copy link
Contributor

commented Sep 22, 2014

I think BodyConsumedError is preferable to EOFError and StreamConsumedError might be even more obvious in this case.

@sigmavirus24

This comment has been minimized.

Copy link
Contributor

commented Sep 22, 2014

Thoughts on making whichever error name we choose multiply inherit from RequestException and TypeError? People who are doing this may already be catching TypeError, if we magically change this on them, it's a breaking change

@Lukasa

This comment has been minimized.

Copy link
Member

commented Sep 22, 2014

Yeah, I can accept that. And StreamConsumedError is the best of the bunch so far.

@sigmavirus24

This comment has been minimized.

Copy link
Contributor

commented Sep 22, 2014

@tijko so could you update this PR to add the described exception to requests/exceptions.py and then use it here where you're raising the RuntimeError? Thanks in advance

tijko added 2 commits Sep 22, 2014
@@ -89,3 +89,6 @@ class ChunkedEncodingError(RequestException):

class ContentDecodingError(RequestException, BaseHTTPError):
"""Failed to decode response content"""

class StreamConsumedError(RequestException):

This comment has been minimized.

Copy link
@sigmavirus24

sigmavirus24 Sep 22, 2014

Contributor

This needs to doubly inherit, like so:

class StreamConsumedError(RequestException, TypeError):
@kennethreitz

This comment has been minimized.

Copy link
Contributor

commented Oct 5, 2014

@sigmavirus24 looks like @tijko updated this as requested

@sigmavirus24

This comment has been minimized.

Copy link
Contributor

commented Oct 5, 2014

@kennethreitz looks good to me

kennethreitz added a commit that referenced this pull request Oct 5, 2014
Merge pull request #2241 from tijko/master
raise RuntimeError when a single streamed request calls *iter methods th...

@kennethreitz kennethreitz merged commit 65cdccb into psf:master Oct 5, 2014

1 check passed

default Merged build finished.
Details
@Harmon758 Harmon758 referenced this pull request Apr 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.