准备用HTTP 在局域网内 上传一些文件,文件一般都在1G左右
r = requests.post('****',
data={'path':'2016/07/08/5ASD5SDFASDFASDF/cad.zip'},
files={'file': open(filename, 'rb')}
)
这样上传小文件可以, 但是上传大文件时候会py会报 memeryError的内存错误。
如何解决此问题呢?
用了个扩展库,可以完美解决2个问题 requests_toolbelt
建设楼主使用requests的流式上传。
以下是一些说明
Streaming Uploads
Requests supports streaming uploads, which allow you to send large streams or files without reading them into memory. To stream and upload, simply provide a file-like object for your body:
http://www.python-requests.org/en/master/user/advanced/#streaming-uploads
推荐你使用poster模块
https://atlee.ca/software/poster/