【发布时间】:2023-12-29 13:03:01
【问题描述】:
我正在尝试使用 Python 2 从服务器下载一个大文件:
req = urllib2.Request("https://myserver/mylargefile.gz")
rsp = urllib2.urlopen(req)
data = rsp.read()
服务器使用“Transfer-Encoding: chunked”发送数据,我只得到一些二进制数据,无法通过 gunzip 解包。
我必须遍历多个 read() 吗?还是多个请求?如果是这样,它们的外观如何?
注意:我正在尝试仅使用 Python 2 标准库来解决问题,而不使用 urllib3 或 requests 等其他库。这甚至可能吗?
【问题讨论】:
标签: python download urllib2 chunked transfer-encoding