簡體   English   中英

Python request.post給出500響應

[英]Python request.post gives 500 response

對於我的一個帖子請求,每次嘗試運行它時都會收到500響應。 當我在郵遞員中復制並粘貼細節時,每次都可以正常工作。 python post適用於我運行的其他請求,但每次都失敗,我無法解決原因。

有沒有人遇到過這個問題,或者有人能看到我做錯了嗎?

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

郵遞員看起來如下:

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

嘗試自吹自擂

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

在Postman中,自動使用Content-Type - application / json

如果使用請求發布json數據,應該使用json = data

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

解決了我的問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM