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

@tijko tijko commented Sep 22, 2014

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

@Lukasa
Copy link
Member

Lukasa 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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@kevinburke
Copy link
Contributor

EOFError?

@sigmavirus24
Copy link
Contributor

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

@sigmavirus24
Copy link
Contributor

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
Copy link
Member

Lukasa commented Sep 22, 2014

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

@sigmavirus24
Copy link
Contributor

@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

@@ -89,3 +89,6 @@ class ChunkedEncodingError(RequestException):

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

class StreamConsumedError(RequestException):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to doubly inherit, like so:

class StreamConsumedError(RequestException, TypeError):

@kennethreitz
Copy link
Contributor

@sigmavirus24 looks like @tijko updated this as requested

@sigmavirus24
Copy link
Contributor

@kennethreitz looks good to me

kennethreitz added a commit that referenced this pull request Oct 5, 2014
raise RuntimeError when a single streamed request calls *iter methods th...
@kennethreitz kennethreitz merged commit 65cdccb into psf:master Oct 5, 2014
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants