If the response is in json you could do something like (python3):
Copyimport json
import requests as reqs
# Make the HTTP request.
response = reqs.get('https://demo.ckan.org/api/3/action/group_list')
# Use the json module to load CKAN's 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__:
Copyprint(response.__dict__)
Edit in May 2024 to add a suggestion on how to address if objects in the response dict is not JSON serializable.
Copyimport json
...
print(json.dumps(response.text, indent=4, sort_keys=True, default=lambda o:'<not serializable>'))
Answer from Jortega on Stack OverflowIf the response is in json you could do something like (python3):
Copyimport json
import requests as reqs
# Make the HTTP request.
response = reqs.get('https://demo.ckan.org/api/3/action/group_list')
# Use the json module to load CKAN's 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__:
Copyprint(response.__dict__)
Edit in May 2024 to add a suggestion on how to address if objects in the response dict is not JSON serializable.
Copyimport json
...
print(json.dumps(response.text, indent=4, sort_keys=True, default=lambda o:'<not serializable>'))
If you push, for example image, to some API and want the result address(response) back you could do:
Copyimport requests
url = 'https://uguu.se/api.php?d=upload-tool'
data = {"name": filename}
files = {'file': open(full_file_path, 'rb')}
response = requests.post(url, data=data, files=files)
current_url = response.text
print(response.text)
Videos
Hi! This is my first post, so let me know if I make any mistake! Also, it's the first time I try to develop anything web using python :) . Anyway, my problem: I'm tryin to develop an app that lets me know when a bus is near my home. I'm taking the gps info from another app, developed by the city. I've been using Fiddler on windows to see how the app comunicates with the remote server. The thing is, I can get the response body from Fiddler manually, but I don't know how to get it from my Python code!
This is a snapshot from Fiddler on my pc.
IMG
Behind the "Save> Response> Response body" you can see the information that I'm trying to get. Any help is useful, thank you so much!
I know responses are usually for GET requests, however in the chrome network tab this is a POST request with a response.
I tried:
print(response.text)
print(response.content)
print(response.json())
but none of these worked.
So how can I get the response object of a POST request? I can only seem to do it for GET requests