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 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:

This comment has been minimized.

@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
Copy link
Contributor

@kevinburke kevinburke commented Sep 22, 2014

EOFError?

@sigmavirus24
Copy link
Contributor

@sigmavirus24 sigmavirus24 commented Sep 22, 2014

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

@sigmavirus24
Copy link
Contributor

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

@Lukasa Lukasa commented Sep 22, 2014

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

@sigmavirus24
Copy link
Contributor

@sigmavirus24 sigmavirus24 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

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

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

class StreamConsumedError(RequestException):

This comment has been minimized.

@sigmavirus24

sigmavirus24 Sep 22, 2014
Contributor

This needs to doubly inherit, like so:

class StreamConsumedError(RequestException, TypeError):
@kennethreitz
Copy link
Contributor

@kennethreitz kennethreitz commented Oct 5, 2014

@sigmavirus24 looks like @tijko updated this as requested

@sigmavirus24
Copy link
Contributor

@sigmavirus24 sigmavirus24 commented Oct 5, 2014

@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
1 check passed
1 check passed
@kennethreitz
default Merged build finished.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants