Skip to content
Merged
Show file tree
Hide file tree
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: 3 additions & 2 deletions nextstrain/cli/pathogens.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,11 @@ def setup(self, dry_run: bool = False, force: bool = False) -> SetupStatus:
""") from err

except requests.exceptions.HTTPError as err:
assert err.response is not None
if 400 <= err.response.status_code <= 499:
auth = err.response.request.headers["Authorization"]
if (err.response.status_code in {401, 403}
and (auth := err.response.request.headers["Authorization"])
and isinstance(auth, str)
and auth.startswith("Basic ")):
user = b64decode(auth.split(" ", 1)[1]).decode("utf-8").split(":", 1)[0]

Expand Down Expand Up @@ -536,7 +538,6 @@ def setup(self, dry_run: bool = False, force: bool = False) -> SetupStatus:
may be worth waiting a little bit and trying again a few
more times.
""", urls = request_list(err.response)) from err

else:
raise err

Expand Down
8 changes: 4 additions & 4 deletions nextstrain/cli/remote/nextstrain_dot_org.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ def download(url: URL, local_path: Path, recursively: bool = False, dry_run: boo
continue

# Stream response data to local file
with destination.open("w") as local_file:
for chunk in response.iter_content(chunk_size = None, decode_unicode = True):
with destination.open("wb") as local_file:
for chunk in response.iter_content(chunk_size = None):
local_file.write(chunk)


Expand Down Expand Up @@ -824,7 +824,7 @@ def raise_for_status(origin: Origin, response: requests.Response) -> None:
response.raise_for_status()

except requests.exceptions.HTTPError as err:
assert type(err.response) is requests.Response
assert err.response is not None
status = err.response.status_code

if status == 400:
Expand Down Expand Up @@ -933,7 +933,7 @@ def raise_for_status(origin: Origin, response: requests.Response) -> None:
raise


def authn_challenge(response: requests.Response) -> Optional[Dict[str, str]]:
def authn_challenge(response: requests.Response) -> Optional[dict[str, Optional[str]]]:
"""
Extract the Bearer authentication challenge parameters from the HTTP
``WWW-Authenticate`` header of *response*.
Expand Down
2 changes: 1 addition & 1 deletion nextstrain/cli/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def default_user_agent(minimal: bool = USER_AGENT_MINIMAL) -> str:

tty = "yes" if any(os.isatty(fd) for fd in [0, 1, 2]) else "no"

return f"Nextstrain-CLI/{__version__} (https://nextstrain.org/cli) Python/{py_version} python-requests/{requests.__version__} platform/{system}-{machine} installer/{installer} tty/{tty}"
return f"Nextstrain-CLI/{__version__} (https://nextstrain.org/cli) Python/{py_version} python-requests/{requests.__version__} platform/{system}-{machine} installer/{installer} tty/{tty}" # type: ignore[reportPrivateImportUsage]


def version_info_to_str(version_info: Tuple[int, int, int, str, int]) -> str:
Expand Down
Loading