python 3.2上的http.client.HTTPConnection可以下载大约1G的大文件吗? 我得到了 HTTPResponse 类的来源 当我读取内容时,所有数据都会保存到变量并返回,变量可以保存1G数据到内存吗?
我想保存数据以将套接字排序为隧道,我在 HTTPResponse 上没有看到 Yield 关键字?
http.client.HTTPConnection 可以运行此任务吗? 谢了:D
最佳答案
分块读取响应。它可以下载它们。
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
关于python - python 3.2 http.client.HTTPConnection 可以下载大文件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15738184/