使用龙卷风 AsyncHTTPClient streaming_callback 下载大文件失败

Downloading large files with tornado AsyncHTTPClient streaming_callback fails

下面的代码适用于小文件(<100MB 左右),但不适用于较大的文件(取消注释第 5 行中的第二个 URL 以查看问题)。令我感到困惑的是,失败是立竿见影的,我猜龙卷风一看到 Content-Length header——但据我了解,streaming_callback 应该使它与 arbitrarily-large 一起工作文件。

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=<_io.BytesIO object at 0x7f7a57563258>,code=200,effective_url='https://www.python.org/ftp/python/2.7.13/python-2.7.13.msi',error=None,headers=,reason='OK',request=,request_time=0.7110521793365479,time_info={})

使用 Python 下载时,但是

0 HTTPResponse(_body=None,buffer=None,code=599,effective_url='http://releases.ubuntu.com/16.04.1/ubuntu-16.04.1-desktop-amd64.iso?_ga=1.179801251.666251388.1483725275',error=HTTP 599: Connection closed,headers=,reason='Unknown',request=,request_time=0.10775566101074219,time_info={})

尝试 Ubuntu 时...

streaming_callback 可以处理任何大小的文件,但默认情况下 AsyncHTTPClient 仍然强制执行 100MB 的限制。要增加它,请使用

AsyncHTTPClient.configure(None, max_body_size=1000000000)