简体   繁体   中英

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"}

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

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

解决了我的问题

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM