Skip to content

Commit

Permalink
[generator] Fixed download_file()
Browse files Browse the repository at this point in the history
  • Loading branch information
maksimandrianov authored and milchakov committed Jan 14, 2021
1 parent 3f66ec6 commit 6cdfd4c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions tools/python/maps_generator/utils/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,14 @@ def download_file(url: AnyStr, name: AnyStr, download_if_exists: bool = True):
session.mount("file://", FileAdapter())
with open(tmp_name, "wb") as handle:
response = session.get(url, stream=True)
file_length = int(response.headers["Content-Length"])
file_length = None
try:
file_length = int(response.headers["Content-Length"])
except KeyError:
logger.warning(
f"There is no attribute Content-Length in headers [{url}]: {response.headers}"
)

current = 0
max_attempts = 32
attempts = max_attempts
Expand All @@ -63,7 +70,7 @@ def download_file(url: AnyStr, name: AnyStr, download_if_exists: bool = True):
current += len(data)
handle.write(data)

if file_length == current:
if file_length is None or file_length == current:
break

logger.warning(
Expand Down

0 comments on commit 6cdfd4c

Please sign in to comment.