把卷曲转置到请求.pu

2024-06-01 10:30:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我想转换curl命令(将本地文件上载到rackspace)

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请求。到目前为止,我已经:

^{pr2}$

在哪里指定要上载screenies/hello.jpg?在

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


Tags: 文件https命令tokenauthhelloputftp
1条回答
网友
1楼 · 发布于 2024-06-01 10:30:00

不,-T只是表示“上载此文件”,这可以与FTP一起使用,但不限于此。在

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

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

其中data将为您读取并上载图像数据。在

相关问题 更多 >