Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print response JSON from server with HTTP POST

How can I get respon JSON dictionaries from server with POST:

import json
import requests

url = 'http://apiurl.com'        
parameters = {'code':1,
              'user': 'username',
              'password': 'password'
              }

headers = {'content-type': 'application/json'} 
response = requests.post(url, data = json.dumps(parameters),headers=headers)
print(response)

output: Response [200]

like image 935
BarryV Avatar asked Feb 05 '26 00:02

BarryV


2 Answers

response = requests.post(url, data=json.dumps(parameters), headers=headers)
print(response)
print(response.text)
like image 101
Mangu Singh Rajpurohit Avatar answered Feb 06 '26 13:02

Mangu Singh Rajpurohit


Since, you are going to receive a JSON object you can simply use request's built-in JSON decoder Simply do:

j = response.json()
like image 45
JRodDynamite Avatar answered Feb 06 '26 14:02

JRodDynamite



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!