2013-04-01 80 views
1

python 3.2上的http.client.HTTPConnection可以下載1G左右的大文件嗎? 當我讀取內容時,所有數據將保存到變量並返回它,可以將變量保存1G數據到內存嗎?我得到的類HTTPResponse的來源 ?可以python 3.2 http.client.HTTPConnection下載大文件?

我想保存數據來訂購socket作爲隧道,我沒有看到yield關鍵字任何地方HTTPResponse?

可以通過http.client.HTTPConnection運行這個任務嗎? tks:D

回答

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