【发布时间】:2011-10-05 13:46:26
【问题描述】:
如果 http 响应不包含 Content-Length 标头,我如何使用 python 正确下载文件?
我在 appengine 的 send_blob() 函数中遇到了这个问题,由于某种原因,它不会在更大 (20mb+) 的 blob 上添加 Content-Length 标头。
现在我正在使用 urllib.urlretrieve() 但有时它不会下载整个文件。 我现在正在做的是在下载文件之前发送内容长度,这样我就可以在继续之前检查文件的大小是否正确。
我不确定是否有更好的方法来做到这一点。
其中一个文件的标题:
HTTP/1.1 200 OK
Cache-Control: no-cache
Content-Type: application/octet-stream
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Date: Fri, 30 Sep 2011 19:41:34 GMT
Server: Google Frontend
Transfer-Encoding: Identity
Connection: close
我只是尝试使用 wget 下载带有wget --server-response --continue 的文件,并且标题是:
HTTP/1.1 200 OK
Cache-Control: no-cache
Content-Type: application/octet-stream
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Date: Wed, 05 Oct 2011 14:08:13 GMT
Server: Google Frontend
Transfer-Encoding: chunked
Length: unspecified [application/octet-stream]
【问题讨论】:
-
关闭 HTTP 连接(从服务器端)是否有效? (不确定这是否会产生明确定义的行为,但这是我的最佳猜测)
-
当它不发送
Content-Length时,是使用Transfer-Encoding: chunked吗? -
@ninjagecko:实际上不知道在使用 send_blob() 函数时是否可以手动关闭连接。
-
@SteveJessop:我通过添加与这些文件之一一起发送的标题来编辑问题。
标签: python google-app-engine download