Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.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 2.7 从cUrl到python2.7_Python 2.7_Curl - Fatal编程技术网

Python 2.7 从cUrl到python2.7

Python 2.7 从cUrl到python2.7,python-2.7,curl,Python 2.7,Curl,我需要将以下cUrl命令转换为Python 2.7: curl -X POST --data-binary @myfile http://127.0.0.1/process/my/data 我在谷歌上搜索了这个,但我只找到了发布字段或文件的示例,而没有将文件内容发送到请求的正文中。对于那些感兴趣的人,以下是答案: # -*- coding: utf-8 -*- import httplib2 h = httplib2.Http(".cache") resp, content = h.requ

我需要将以下cUrl命令转换为Python 2.7:

curl -X POST --data-binary @myfile http://127.0.0.1/process/my/data

我在谷歌上搜索了这个,但我只找到了发布字段或文件的示例,而没有将文件内容发送到请求的
正文中。

对于那些感兴趣的人,以下是答案:

# -*- coding: utf-8 -*-
import httplib2

h = httplib2.Http(".cache")
resp, content = h.request("http://127.0.0.1/requests", 
    "POST", body="Here is the content of the file you want to post",
    headers={'Content-type': 'application/json'}
    )    
print resp

为什么是-1?,你能解释一下吗?。