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

Add support for response.raw attribute. #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

seibert
Copy link

@seibert seibert commented Jun 27, 2014

Response objects in requests are documented to contain a raw attribute that is a file-like object. When the request is made with stream=True, the raw attribute can be read to stream in the content. Otherwise, the raw attribute looks like a file-like object with no bytes left to read.

This PR adds support for the raw attribute and its behavior (at least how requests behaves currently).

@seibert seibert mentioned this pull request Jun 27, 2014
try:
from cStringIO import StringIO
except ImportError:
from io import StringIO
Copy link
Owner

Choose a reason for hiding this comment

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

Won't you need a third fallback here for from StringIO import StringIO on Python 2 platforms that do not support cStringIO?

@garyvdm
Copy link
Contributor

garyvdm commented Jul 4, 2014

I feel this implementation is incorrect. It should use BytesIO and not StringIO, so that r.raw.read() returns bytes on Python 3.

I'm working on a patch for it.

@seibert
Copy link
Author

seibert commented Jul 4, 2014

You are correct. I should have used BytesIO for Python 2 and 3 compatibility.

@patrys
Copy link
Owner

patrys commented Aug 29, 2014

Any news here? ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants