Reputation: 75
I am trying to send a JSON object using python but I am getting 422 error. Meanwhile, with postman I am able to post the JSON via the API: First I enter the authentication in the Authorization and in the body I specify raw and choose JSON then I post the JSON object and get a 200 response.
But with python:
endpoint = "some endpoint"
url = host + endpoint
headers={"Accept": "application/json",
"Authorization": f"Bearer {bearer_token}"}
order = json.dumps(json_object, ensure_ascii=False)
send_data = requests.post(url, json=order, headers=headers)
print(send_data.json())
if send_data.status_code==200:
print("Order successfully sent")
else:
print(f"The following error was encountered. Error: {send_data.status_code}")
What could be wrong? please advise
Upvotes: 0
Views: 298
Reputation: 1925
try
headers={"Accept": "application/json",
"Authorization": f"Bearer {bearer_token}"}
send_data = requests.post(url, data=order, headers=headers)
Upvotes: 1