Skip to content

Commit

Permalink
fix download bugs
Browse files Browse the repository at this point in the history
- if http request fails, remove the target file automatically but not leave a empty target file
- download decoded content but not raw content
  • Loading branch information
CunliangGeng committed Oct 30, 2023
1 parent 4d230e9 commit e94ffaa
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/nplinker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def download_url(url: str,
url,
follow_redirects=allow_http_redirect) as response:
if not response.is_success:
fpath.unlink(missing_ok=True)
raise RuntimeError(
f"Failed to download url {url} with status code {response.status_code}"
)
Expand All @@ -182,7 +183,7 @@ def download_url(url: str,
unit_divisor=1024,
unit="B") as progress:
num_bytes_downloaded = response.num_bytes_downloaded
for chunk in response.iter_raw():
for chunk in response.iter_bytes():
fh.write(chunk)
progress.update(response.num_bytes_downloaded -
num_bytes_downloaded)
Expand Down

0 comments on commit e94ffaa

Please sign in to comment.