How to extract HTTP response body from a Python requests call?

How to extract HTTP response body from a Python requests call?

Your code is correct. I tested:

r = requests.get(http://www.google.com)
print(r.content)

And it returned plenty of content.
Check the url, try http://www.google.com. Cheers!


import requests

site_request = requests.get(https://abhiunix.in)

site_response = str(site_request.content)

print(site_response)

You can do it either way.

How to extract HTTP response body from a Python requests call?

You can try this method:

import requests

response = requests.get(http://www.google.com)
response.raise_for_status()

data = response.json()
print(data)

Leave a Reply

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