Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix error on downloading URL with 302 redirect #212

Merged
merged 2 commits into from
Nov 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading