This is how it works with wget (anonymized host names and IPs):
Код: Выделить всё
$ wget
--2020-02-17 11:09:18--
Resolving ()...
Connecting to ()||:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 31581872 (30M) [application/x-gzip]
Saving to: ‘[...]’
< /code>
Это также прекрасно работает с флагом-continue < /code>, чтобы возобновить загрузку, включая пропуск, если файл был полностью загружен ранее.$ curl -I
HTTP/2 200
date: Mon, 17 Feb 2020 13:11:55 GMT
server: Apache/2.4.25 (Debian)
strict-transport-security: max-age=15768000
last-modified: Fri, 14 Feb 2020 15:42:29 GMT
etag: "[...]"
accept-ranges: bytes
content-length: 31581872
vary: Accept-Encoding
content-type: application/x-gzip
< /code>
В Python я пытаюсь реализовать ту же логику, проверив заголовок содержимого < /code>, используя библиотеку запросов: < /p>
with requests.get(url, stream=True) as response:
total_size = int(response.headers.get("Content-length"))
if not response.ok:
logger.error(
f"Error {response.status_code} when downloading file from {url}"
)
elif os.path.exists(file) and os.stat(file).st_size == total_size:
logger.info(f"File '{file}' already exists, skipping download.")
else:
[...] # download file
Код: Выделить всё
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
< /code>
Я могу вручную подтвердить, что заголовок содержимого < /code> нет: < /p>
requests.get(url, stream=True).headers
{'Date': '[...]', 'Server': '[...]', 'Strict-Transport-Security': '[...]', 'Upgrade': '[...]', 'Connection': 'Upgrade, Keep-Alive', 'Last-Modified': '[...]', 'ETag': ''[...]'', 'Accept-Ranges': 'bytes', 'Vary': 'Accept-Encoding', 'Content-Encoding': 'gzip', 'Keep-Alive': 'timeout=15, max=100', 'Transfer-Encoding': 'chunked', 'Content-Type': 'application/x-gzip'}
Подробнее здесь: https://stackoverflow.com/questions/602 ... n-requests