Skip to content

Commit

Permalink
Merge pull request #212 from Laubeee/patch-1
Browse files Browse the repository at this point in the history
fix error on downloading URL with 302 redirect
  • Loading branch information
goodmami authored Nov 1, 2024
2 parents 8ea1e27 + c6de241 commit ac1896a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion wn/_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def _get_cache_path_and_urls(project_or_url: str) -> tuple[Optional[Path], list[


def _download(urls: Sequence[str], progress: ProgressHandler) -> Path:
client = httpx.Client(timeout=TIMEOUT, follow_redirects=True)
try:
for i, url in enumerate(urls, 1):
path = config.get_cache_path(url)
Expand All @@ -98,7 +99,7 @@ def _download(urls: Sequence[str], progress: ProgressHandler) -> Path:
try:
with open(path, 'wb') as f:
progress.set(status='Requesting', count=0)
with httpx.stream("GET", url, timeout=TIMEOUT) as response:
with client.stream("GET", url) as response:
response.raise_for_status()
total = int(response.headers.get('Content-Length', 0))
count = response.num_bytes_downloaded
Expand Down Expand Up @@ -128,5 +129,7 @@ def _download(urls: Sequence[str], progress: ProgressHandler) -> Path:
except Exception:
path.unlink(missing_ok=True)
raise
finally:
client.close()

return path

0 comments on commit ac1896a

Please sign in to comment.