Print response JSON from server with HTTP POST

10,621

Solution 1

response = requests.post(url, data=json.dumps(parameters), headers=headers)
print(response)
print(response.text)

Solution 2

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

j = response.json()
Share:
10,621
BarryV
Author by

BarryV

Updated on June 04, 2022

Comments

  • BarryV
    BarryV almost 2 years

    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]