python - python通过请求上传文件
问题描述
当我使用 curl 将数据上传到服务器时,一切正常,但是当我在 python 中使用请求时,api 服务器不接受请求。
块引用
卷曲:
curl -X POST https://tapi.bale.ai/botXXX/Senddocument \
-H 'content-type: multipart/form-data' \
-F chat_id=2040137555 \
-F document=@/var/tmp/2706021400.pdf \
-F caption=caption
要求:
import requests
headers = {
'content-type': 'multipart/form-data',
}
files = {
'chat_id': (None, '2040137555'),
'document': ('/var/tmp/2706021400.pdf', open('/var/tmp/2706021400.pdf', 'rb')),
'caption': (None, 'caption'),
}
response = requests.post('https://tapi.bale.ai/botXXX/Senddocument', headers=headers, files=files)
解决方案
推荐阅读
- ibm-watson - Watson Language Translator 服务是否支持不应翻译的变量
- winapi - 如何获取当前机器的 SID?
- php - Windows 上的 PHP 或 Python 向远程 Linux 堆栈发送命令
- sql - oracle 中的 CASE WHEN 表达式
- android - 任务 ':app:kaptGenerateStubsFossDebugKotlin' 执行失败。> 内部编译器错误
- javascript - 我可以为同一个 es lint 规则强制执行多个级别吗?例如:不同路径的错误和警告
- compression - 使用 DEFLATE 压缩文本文件时,需要多少数据才能减小大小?
- c - 在给定的 BST 中查找最大子树,使其没有重复项
- css - Bootstrap 列宽调整
- python - 递归特征消除后无法进行预测