1

python 3.2上的http.client.HTTPConnection可以下载1G左右的大文件吗?当我读取内容时,我得到了类 HTTPResponse 的源,所有数据都会保存到变量并返回,变量可以将 1G 数据保存到内存吗?

我想保存数据以将套接字订购为隧道,我在 HTTPResponse 的任何地方都看不到 yield 关键字?

http.client.HTTPConnection 可以运行这个任务吗?传统知识:D

4

1 回答 1

2

分块阅读响应。它可以下载它们。

import http.client
conn = http.client.HTTPConnection("www.python.org")
conn.request("GET", "/index.html")
r1 = conn.getresponse()
print(r1.status, r1.reason)

data1 = r1.read()  # This will return entire content.
# The following example demonstrates reading data in chunks.
conn.request("GET", "/index.html")
r1 = conn.getresponse()
while not r1.closed:
    print(r1.read(200)) # 200 bytes
于 2013-04-01T05:39:18.993 回答