栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Python请求-发布包含multipart / form-data的zip文件

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python请求-发布包含multipart / form-data的zip文件

requests
目前而言,zip文件与任何其他二进制数据块之间 没有区别

您的 服务器 在这里坏了;当您发送一个zip文件时,它切断了连接。那是

requests
无能为力的。

http://httpbin.org/
当您遇到此类问题时,您可能需要进行测试;它是
requests
库作者构建的测试服务。

另一个提示:发送时不需要将整个文件对象读入内存。只需将对象本身传递给

requests

fileobj = open('/Users/.../test.zip', 'rb')r = requests.post(url, auth=HTTPDigestAuth('dev', 'dev'), data = {"mysubmit":"Go"}, files={"archive": ("test.zip", fileobj)})

针对的演示

httpbin.org

>>> import requests>>> fileobj = open('/tmp/test.zip', 'rb')>>> r = requests.post('http://httpbin.org/post', data={"mysubmit":"Go"}, files={"archive": ("test.zip", fileobj)})>>> r<Response [200]>>>> r.json(){u'origin': u'217.32.203.188', u'files': {u'archive': u'data:application/zip;base64,<long base64 body omitted>'}, u'form': {u'mysubmit': u'Go'}, u'url': u'http://httpbin.org/post', u'args': {}, u'headers': {u'Content-Length': u'57008', u'Accept-Encoding': u'gzip, deflate, compress', u'Connection': u'close', u'Accept': u'*/*', u'User-Agent': u'python-requests/1.2.3 CPython/2.7.5 Darwin/12.4.0', u'Host': u'httpbin.org', u'Content-Type': u'multipart/form-data; boundary=9aec1d03a1794177a38b48416dd4c811'}, u'json': None, u'data': u''}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/661079.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号