我已经检查了很多代码片段,但我无法了解如何仅使用 python 2.4 在单个请求中发布多部分文本和二进制文件?这里在评论中提到了一些关于 BytesIO 类的内容,但在 2.4 中不存在。(纯python,没有第三方库)谢谢。
问问题
803 次
1 回答
0
使用 Python 2.6,您可以使用 requests 库,这是从文档中提取的片段:
>>> url = 'http://httpbin.org/post'
>>> files = {'report.xls': open('report.xls', 'rb')}
>>> r = requests.post(url, files=files)
>>> r.text
{
"origin": "179.13.100.4",
"files": {
"report.xls": "<censored...binary...data>"
},
"form": {},
"url": "http://httpbin.org/post",
"args": {},
"headers": {
"Content-Length": "3196",
"Accept-Encoding": "identity, deflate, compress, gzip",
"Accept": "*/*",
"User-Agent": "python-requests/0.8.0",
"Host": "httpbin.org:80",
"Content-Type": "multipart/form-data; boundary=127.0.0.1.502.21746.1321131593.786.1"
},
"data": ""
}
于 2012-01-25T21:03:53.107 回答