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

Projects
None yet
5 participants
@tijko
Contributor

tijko 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.

Show comment
Hide comment
@Lukasa

Lukasa Sep 22, 2014

Member

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

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?

Show outdated Hide outdated requests/models.py
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.

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

Show comment
Hide comment
@kevinburke

kevinburke Sep 22, 2014

Contributor

EOFError?

Contributor

kevinburke commented Sep 22, 2014

EOFError?

@sigmavirus24

This comment has been minimized.

Show comment
Hide comment
@sigmavirus24

sigmavirus24 Sep 22, 2014

Member

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

Member

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

Show comment
Hide comment
@sigmavirus24

sigmavirus24 Sep 22, 2014

Member

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

Member

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

This comment has been minimized.

Show comment
Hide comment
@Lukasa

Lukasa Sep 22, 2014

Member

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

Member

Lukasa 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.

Show comment
Hide comment
@sigmavirus24

sigmavirus24 Sep 22, 2014

Member

@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

Member

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

Show outdated Hide outdated requests/exceptions.py
@@ -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

Member

This needs to doubly inherit, like so:

class StreamConsumedError(RequestException, TypeError):
@sigmavirus24

sigmavirus24 Sep 22, 2014

Member

This needs to doubly inherit, like so:

class StreamConsumedError(RequestException, TypeError):
@kennethreitz

This comment has been minimized.

Show comment
Hide comment
@kennethreitz

kennethreitz Oct 5, 2014

Member

@sigmavirus24 looks like @tijko updated this as requested

Member

kennethreitz commented Oct 5, 2014

@sigmavirus24 looks like @tijko updated this as requested

@sigmavirus24

This comment has been minimized.

Show comment
Hide comment
@sigmavirus24

sigmavirus24 Oct 5, 2014

Member

@kennethreitz looks good to me

Member

sigmavirus24 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 requests:master Oct 5, 2014

1 check passed

default Merged build finished.
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment