简体   繁体   English

将请求放在curl中,但不在Python中

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

I am trying to make a 'put' method with curl everything is working fine and I got the JSON back: 我正在尝试使用curl制作一个'put'方法,一切正常,我收到了JSON:

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

But for some reason when using the python requests module as follow: 但由于某种原因使用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)

I get the following error: 我收到以下错误:

500 Internal Server Error 500内部服务器错误

Internal Server Error 内部服务器错误

The server encountered an internal error and was unable to complete your request. 服务器遇到内部错误,无法完成您的请求。 Either the server is overloaded or there is an error in the application. 服务器过载或应用程序中存在错误。

NB: The server is up and running. 注意:服务器已启动并正在运行。

The data should be dumped: 应该转储数据:

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

or you can use the json key instead of data : 或者您可以使用json键而不是data

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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