How to download chunked data with Pythons urllib2

前端 未结 3 508
太阳男子
太阳男子 2021-01-06 17:08

I\'m trying to download a large file from a server with Python 2:

req = urllib2.Request(\"https://myserver/mylargefile.gz\")
rsp = urllib2.urlopen(req)
data          


        
3条回答
  •  一生所求
    2021-01-06 18:02

    If I'm not mistaken, the following worked for me - a while back:

    data = ''
    chunk = rsp.read()
    while chunk:
        data += chunk
        chunk = rsp.read()
    

    Each read reads one chunk - so keep on reading until nothing more's coming. Don't have documenation ready supporting this...yet.

提交回复
热议问题