簡體   English   中英

將請求放在curl中,但不在Python中

[英]Put request working in curl, but not in Python

我正在嘗試使用curl制作一個'put'方法,一切正常,我收到了JSON:

curl -X PUT -d '[{"foo":"more_foo"}]' http://ip:6001/whatever?api_key=whatever

但由於某種原因使用python requests模塊如下:

import requests
url = 'http://ip:6001/whatever?api_key=whatever'

a = requests.put(url, data={"foo":"more_foo"})

print(a.text)
print(a.status_code)

我收到以下錯誤:

500內部服務器錯誤

內部服務器錯誤

服務器遇到內部錯誤,無法完成您的請求。 服務器過載或應用程序中存在錯誤。

注意:服務器已啟動並正在運行。

應該轉儲數據:

a = requests.put(url, data=json.dumps([{"foo":"more_foo"}]))

或者您可以使用json鍵而不是data

a = requests.post(url, json=[{"foo":"more_foo"}])

暫無
暫無

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

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