ChrisG29
ChrisG29

Reputation: 1571

Python request.post gives 500 response

For one of my post requests, I get a 500 response every time I try to run it. When I copy and paste the details in postman, it works fine every time. The python post works fine for other requests that I run, but this one fails every time and I can't work out why.

Has anyone come across this problem before, or can anyone see something that I've done wrong?

json_body = '{"overrides": [], "id": 0, "name": "Rate Sheet 12", "resellerId": 2000001, "currency": "ZAR", "markup": {"id": 0, "method": "Percentage", "operand": 3}, "totalLinkedBands": 0, "totalLinkedAccounts": 0}'
token = 'JWT eyJ0eXA...s'
url = 'http://app01:8084//PriceScheme/CreatePriceScheme'
r = requests.post(url, json.loads(json_body), headers={'Authorization': token})

In Postman it looks as follows:

(POST) http://app01:8084//PriceScheme/CreatePriceScheme
Content-Type - application/json
Authorization - JWT eyJ...

{"overrides": [], "name": "Rate Sheet 1", "currency": "ZAR", "totalLinkedAccounts": 0, "totalLinkedBands": 1, "id": 1, "markup": {"method": "Percentage", "operand": 3.0, "id": 0}, "resellerId": "2009340"}

Upvotes: 3

Views: 11806

Answers (2)

Muthu Raman Kannan
Muthu Raman Kannan

Reputation: 1

json_body='{"parametername":Value}' resp = requests.post(URL, json_body, auth=('username', 'Pass'))

Solved the issue in my case

Upvotes: 0

yixing yan
yixing yan

Reputation: 183

try as blew

requests.post(url, json = json_body, headers={'Authorization': token})

In Postman , auto using Content-Type - application/json

If using request post json data , should using json=data

Upvotes: 2

Related Questions