python - 在 python 中通过 requests.put 上传文件
问题描述
我正在尝试使用 requests 模块将以下 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())
推荐阅读
- java - 使用jdk1.8.0时变成
- c# - 如何在 C# 中实现具有子菜单的控制台菜单
- reactjs - 为 NextJS 实现 Apollo 客户端,但无法读取未定义的属性“WebSocket”
- gitlab - 如何将第三方系统连接到 Gitlab 进行身份验证
- c# - 如何简化 It.IsAny
() 用于设置 Mocks 的参数 - php - 无法使相对路径、重写规则和路由的行为符合我的预期
- php - 将json转换为对象php
- python - 构造一个大于任何字符串的对象
- javascript - 在Javascript中自动完成输入日期?
- amazon-web-services - 卓:我的账户会收到意外费用吗?