Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the raw content of a response in requests with Python?

Trying to get the raw data of the HTTP response content in requests in Python. I am interested in forwarding the response through another channel, which means that ideally the content should be as pristine as possible.

What would be a good way to do this?

like image 952
Juan Carlos Coto Avatar asked Jun 04 '13 17:06

Juan Carlos Coto


People also ask

How do I get raw data in Python?

You can use the function raw_input() to read from the standard input and then process as you need. Show activity on this post. use this raw_input() it's the basic python input function.

What is raw response?

Raw enables full control of the response. This can be especially useful when building a REST API call from a Process. Response. Raw responds with a value and optional response headers. The default ContentType is "text/plain; charset=utf-8".


1 Answers

If you are using a requests.get call to obtain your HTTP response, you can use the raw attribute of the response. Here is the code from the requests docs.

>>> r = requests.get('https://github.com/timeline.json', stream=True) >>> r.raw <requests.packages.urllib3.response.HTTPResponse object at 0x101194810> >>> r.raw.read(10) '\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03' 
like image 137
Brien Avatar answered Sep 20 '22 14:09

Brien