How do I read a response from Python Requests?

How do I read a response from Python Requests?

Requests doesnt have an equivalent to Urlib2s read().

>>> import requests
>>> response = requests.get(
>>> print response.content
<!doctype html><html itemscope= itemtype=><head>....
>>> print response.content == response.text

It looks like the POST request you are making is returning no content. Which is often the case with a POST request. Perhaps it set a cookie? The status code is telling you that the POST succeeded after all.

Edit for Python 3:

Python now handles data types differently. response.content returns a sequence of bytes (integers that represent ASCII) while response.text is a string (sequence of chars).


>>> print response.content == response.text

>>> print str(response.content) == response.text

If the response is in json you could do something like (python3):

import json
import requests as reqs

# Make the HTTP request.
response = reqs.get(

# Use the json module to load CKANs response into a dictionary.
response_dict = json.loads(response.text)

for i in response_dict:
    print(key: , i, val: , response_dict[i])

To see everything in the response you can use .__dict__:


How do I read a response from Python Requests?

If you push, for example image, to some API and want the result address(response) back you could do:

import requests
url =
data = {name: filename}
files = {file: open(full_file_path, rb)}
response =, data=data, files=files)
current_url = response.text

Leave a Reply

Your email address will not be published. Required fields are marked *