如何在Python中通过HTTPPost方法发送大文件,上传大文件

时间:2013-07-18 12:03:39

标签: python http post file-upload streaming

我想通过Python中的HTTPPost方法发布巨大的.ova文件

**ResponseHeaders**
Pragma  no-cache
Date    Thu, 18 Jul 2013 11:17:13 GMT
Content-Encoding    gzip
Vary    Accept-Encoding
Server  Apache-Coyote/1.1
Transfer-Encoding   chunked
Content-Language    en-US
Content-Type    application/json;charset=UTF-8
Cache-Control   no-cache, no-store, max-age=0
Expires Thu, 01 Jan 1970 00:00:00 GMT
**RequestHeaders**
Content-Type    application/json
Accept  application/json
xyzAPIVersion   1.0
X-Requested-With    XMLHttpRequest 

如何通过REST API通过HTTPPost方法发送如此庞大的文件(500 MB)。

1 个答案:

答案 0 :(得分:4)

您可以使用requests library

import requests # $ pip install requests

with open("file.ova", "rb") as file:
    requests.post(url, data=file)