2

When using the python module requests to perform requests you can have the response in various formats (according to the documentation):

  • text: Content of the response, in unicode.
  • content: Content of the response, in bytes.

But in some other examples (like here) there is also a property named raw, which is not defined in the documentation.

So what does raw mean?

Alex
  • 41,580
  • 88
  • 260
  • 469

3 Answers3

4

It's documented here:

In the rare case that you’d like to get the raw socket response from the server, you can access r.raw. If you want to do this, make sure you set stream=True in your initial request.

Response.raw

Response.raw is a raw stream of bytes – it does not transform the response content. If you really need access to the bytes as they were returned, use Response.raw.

In Response.content the gzip and deflate transfer-encodings are automatically decoded for you (source).

Fcmam5
  • 4,888
  • 1
  • 16
  • 33
1

File-like object representation of response (for advanced usage). Use of raw requires that stream=True be set on the request. This requirement does not apply for use internally to Requests.

https://github.com/kennethreitz/requests/blob/4983a9bde39c6320aa4f3e34e50dac6e263dab6f/requests/models.py#L609-L612

Sav
  • 616
  • 3
  • 9
0

raw is an attribute of requests.Response instances. It does not seem to be documented in the obvious place, but the source code says

File-like object representation of response (for advanced usage). Use of raw requires that stream=True be set on the request. This requirement does not apply for use internally to Requests.

Leporello
  • 638
  • 4
  • 12
  • Also, one of the answers in the linked questions links to https://2.python-requests.org//en/latest/api/#requests.Response.raw, so presumably the anchor `#requests.Response.raw` existed at some point in time in that doc page. – Leporello Jun 07 '19 at 09:48