下面的代码适用于小文件(<100MB左右),但不能大于(在第5行取消注释第二个URL以查看问题)。令我感到困惑的是,失败是立竿见影的,我想只要龙卷风看到Content-Length标题 - 但根据我的理解,streaming_callback应该让它适用于任意大的文件。
import tornado, tornado.httpclient
def main():
url = "https://www.python.org/ftp/python/2.7.13/python-2.7.13.msi"
# url = "http://releases.ubuntu.com/16.04.1/ubuntu-16.04.1-desktop-amd64.iso?_ga=1.179801251.666251388.1483725275"
client = tornado.httpclient.AsyncHTTPClient()
request = tornado.httpclient.HTTPRequest(url=url, streaming_callback=on_chunk)
client.fetch(request,on_done)
total_data = 0
def on_done(response):
print total_data
print response
def on_chunk(chunk):
global total_data
total_data += len(chunk)
main()
tornado.ioloop.IOLoop.current().start()
我明白了:
19161088 HTTPResponse(_body = None,buffer =&lt; _io.BytesIO object at 0x7f7a57563258&gt;,code = 200,effective_url =&#39; https://www.python.org/ftp/python/2.7.13/python-2.7.13.msi&#39;,error = None,headers =,reason =&#39 ; OK&#39;,请求=,= REQUEST_TIME 0.7110521793365479,time_info = {})
下载Python时,但
0 HTTPResponse(_body =无,缓冲区=无,代码= 599,effective_url =&#39; http://releases.ubuntu.com/16.04.1/ubuntu-16.04.1-desktop-amd64.iso?_ga=1.179801251.666251388.1483725275&#39;,错误= HTTP 599:连接已关闭,标头=,原因=&#39;未知&#39 ;,请求=,= REQUEST_TIME 0.10775566101074219,time_info = {})
尝试使用Ubuntu时...
答案 0 :(得分:0)
streaming_callback
可以使用任何大小的文件,但默认情况下AsyncHTTPClient
仍然可以强制执行100MB的限制。要增加此功能,请使用
AsyncHTTPClient.configure(None, max_body_size=1000000000)