即使我使用requests.put()
,服務器也將它的請求識別爲「GET」。request.put()但它請求使用PUT在我的Python上使用GET
這是我的代碼。
import requests
import json
url = 'https://api.domain.com/test/partners/digital-pie/users/assignee'
payload = """
{
"assignee": {
"district": "3",
"phone": "01010001000",
"carNum": "598865"
},
"deduction": {
"min": 1000,
"max": 2000
},
"meta": {
"unit-label": "1-1-1",
"year": "2017",
"quarter": "2"
}
}
"""
headers = {"content-type": "application/json", "x-api-key": "test_api_dp" }
r = requests.put(url, data=json.dumps(payload), headers=headers)
print("status code:", r.status_code)
print('encoding:', r.encoding)
print('text:', r.text)
print('json:', r.json())
當我通過wireshark檢查包時,我可以知道我的代碼請求爲「GET」。
哪個是錯我的代碼?
增加了更多。
我修正了下面的代碼,發現302重定向是通過檢查r.history發生的。 但仍然堅持爲什麼302發生。
當我比較郵差。它顯示正確。
除了第2位。 requests variable watch window
'requests.put()'肯定發送'PUT'方法。你確定服務器沒有響應'302'或'303'重定向嗎? –
您在截圖中顯示的GET請求**與您的請求**不符。 PUT進入'/ test/partners/digital-pie/users/assignee',GET用於'/ partners/digital-pie/users/assignee'。我還注意到,該服務器以404請求響應該GET請求。 –
注意:當使用'json = payload'而不是'data'時,不需要使用'json.dumps()'或設置Content-Type'頭。 –