如果http響應不包含Content-Length頭文件,我該如何正確使用python下載文件?如果沒有提供Content-Length,用python正確下載文件
即時通訊問題與appengine的send_blob()函數由於某種原因不會在較大(20mb +)blob添加內容長度標頭。
現在我使用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連接(從服務器端)工作? (不確定是否會產生明確定義的行爲,但這是我最好的猜測) – ninjagecko
當它不發送Content-Length時,它是否使用Transfer-Encoding:chunked? –
@ninjagecko:實際上並不知道在使用send_blob()函數時是否可以手動關閉連接。 – aschmid00