Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python post请求与curl工具的比较_Python_Curl - Fatal编程技术网

python post请求与curl工具的比较

python post请求与curl工具的比较,python,curl,Python,Curl,在我的项目中 我曾经 curl -I url -H"Content-Type: application/octet-stream" -X POST 一切正常 但在python中,我使用了请求模块 response = requests.post(url, data="mystring", headers="Content-Type: application/octet-stream") 然后我得到了400个错误,这意味着:请求错误;请求的格式不正确,无法处理 可能是什么问题?您确定curl和

在我的项目中

我曾经

curl -I url -H"Content-Type: application/octet-stream" -X POST
一切正常

但在python中,我使用了请求模块

response = requests.post(url, data="mystring", headers="Content-Type: application/octet-stream")
然后我得到了400个错误,这意味着:请求错误;请求的格式不正确,无法处理


可能是什么问题?

您确定curl和请求的url和数据完全相同吗?

尝试一些基本的疑难解答。假设url和数据字符串是正确的。您确定能够访问服务器吗?curl请求是一个终端命令,其连接方式不同于pythonapi类型的命令,python可能需要服务器打开的额外权限。如果您正在运行Apache,则需要确保它允许scirpted头

请阅读以下内容:

还可以尝试使用其他库进行连接的替代方法,如此线程上的人员所做的:

“使用httplib

import httplib
conn = httplib.HTTPConnection("www.google.com")
conn.request("HEAD", "/index.html")
res = conn.getresponse()
print res.status, res.reason
200 OK
print res.getheaders()
[('content-length', '0'), ('expires', '-1'), ('server', 'gws'), ('cache-control', 'private, max-age=0'), ('date', 'Sat, 20 Sep 2008 06:43:36 GMT'), ('content-type', 'text/html; charset=ISO-8859-1')]

是,Url已复制粘贴。因为curl命令中甚至并没有数据,所以它给了我正确的反馈。有什么不同吗?我尝试了python3http.client模块,结果也是一样的。服务器是Nginx。问题是否可能来自服务器端?问题很可能来自服务器端设置。看看这里的文档是否提供了您要寻找的awnsers。