Improve downloading logic

Follow redirects to avoid saving an intermediate response, and raise an
error on invalid status to avoid saving an error response.
This commit is contained in:
Ivan Habunek 2024-08-28 09:52:15 +02:00
parent 141ecb7f29
commit f9e60082ba
No known key found for this signature in database
GPG Key ID: 01DB3DD0D824504C

View File

@ -12,7 +12,8 @@ RETRY_COUNT = 5
def _download(url: str, path: str):
tmp_path = path + ".tmp"
size = 0
with httpx.stream("GET", url, timeout=CONNECT_TIMEOUT) as response:
with httpx.stream("GET", url, timeout=CONNECT_TIMEOUT, follow_redirects=True) as response:
response.raise_for_status()
with open(tmp_path, "wb") as target:
for chunk in response.iter_bytes(chunk_size=CHUNK_SIZE):
target.write(chunk)