【发布时间】:2015-06-29 01:45:36
【问题描述】:
我想在 Python 3 中使用 Python 的 Requests 库在 POST 请求中发送文件。我正在尝试这样发送:
import requests
file_content = 'This is the text of the file to upload'
r = requests.post('http://endpoint',
params = {
'token': 'api_token',
'message': 'message text',
},
files = {'filename': file_content},
)
但是,服务器响应没有发送任何文件。这应该工作吗?大多数示例都涉及传递文件对象,但我不想为了上传它而将字符串写入磁盘。
【问题讨论】:
标签: python python-3.x python-requests