Python请求-发布包含multipartform-data的zip文件

Python请求-发布包含multipartform-data的zip文件,第1张

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''}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5667195.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存