2013-06-22 27 views
1

我想转curl命令(其上传本地文件到Rackspace公司)转卷曲PUT到requests.put

curl -X PUT -T screenies/hello.jpg -D - \ 
-H "X-Auth-Token: fc81aaa6-98a1-9ab0-94ba-aba9a89aa9ae" \ 
https://storage101.dfw1.clouddrive.com/v1/CF_xer7_343/images/hello.jpg 

到Python的请求。到目前为止,我有:

url = 'http://storage.clouddrive.com/v1/CF_xer7_343/images/hello.jpg' 
headers = {'X-Auth-Token': 'fc81aaa6-98a1-9ab0-94ba-aba9a89aa9ae'} 
request = requests.put(url, headers=headers, data={}) 

我在哪里指定我想上传screenies/hello.jpg

据我所知,在curl中-T代表'到FTP服务器',但我搜索了requests's github但找不到FTP的提及。

+0

http://stackoverflow.com/questions/12569545/upload-file-using-python-requests – snahor

回答

1

不,-T只是表示'上传这个文件',其中可以用与FTP一起使用,但不限于此。

您只需上传文件数据作为data参数:

with open('screenies/hello.jpg', 'rb') as image: 
    request = requests.put(url, headers=headers, data=image) 

其中data将读取并上传图像数据为您服务。