在python中通过requests.put上传文件



我正在尝试使用请求模块将以下curl命令转换为python代码。

curl -v -X PUT -T video_file.mp4 https://my-app-domain.com

已经尝试了下面的一些方法,但仍然没有成功。

with open(mp4_file_path, 'rb') as finput:
response = requests.put('https://my-app-domain.com', data=finput)

有人能教我怎么写吗?提前谢谢。

根据这里的文档,数据可以接受"字典、元组列表、字节或类似文件的对象">

这应该有效:

with open(mp4_file_path, 'rb') as finput:
response = requests.put('https://my-app-domain.com', data=finput.read())

最新更新