Repository navigation
Closed
Labels
bugSomething isn't working
Description
Scope
Any device with expired credentials for api.github.com in ~/.netrc.
Description
nextstrain setup measles (and zika) are broken (use --force to reproduce):
$ nextstrain setup measles --force
Setting up measles@main…
Removing existing setup '/Users/vlin/.nextstrain/pathogens/measles/main=NVQWS3Q=' to start fresh…
Error: Failed to download pathogen setup URL:
https://nextstrain.org/pathogen-repos/measles/versions/e1d1541c3ac44bc73da5872a2721d4edd10f9651
⮡ https://api.github.com/repos/nextstrain/measles/zipball/e1d1541c3ac44bc73da5872a2721d4edd10f9651
The server responded with an error:
HTTPError: 401 Client Error: Unauthorized for url: https://api.github.com/repos/nextstrain/measles/zipball/e1d1541c3ac44bc73da5872a2721d4edd10f9651
The URL may be incorrect (e.g. misspelled) or no longer
accessible.The URL works fine through an unauthenticated browser session and curl command. This seems to be an issue with the Python request and is minimally reproducible with:
import requests
requests.get("https://api.github.com/repos/nextstrain/measles/zipball/e1d1541c3ac44bc73da5872a2721d4edd10f9651")
# <Response [401]>Possible solutions
- Ensure the Python request is unauthenticated by setting
requests.Session.trust_env = False. (ref) - ⛔️ Catch exceptions and if status=401 re-try with
trust_env=False. (ref) - ⛔️ Update the nextstrain.org endpoint to redirect to another URL. I found at least 3 alternatives that work.
-
https://codeload.github.com/<org>/<repo>/legacy.zip/<commit>This is actually what the original URL redirects to if it doesn't return
401:curl -o /dev/null -s -D - "https://api.github.com/repos/nextstrain/measles/zipball/e1d1541c3ac44bc73da5872a2721d4edd10f9651" # HTTP/2 302 # location: https://codeload.github.com/nextstrain/measles/legacy.zip/e1d1541c3ac44bc73da5872a2721d4edd10f9651
Example:
requests.get("https://codeload.github.com/nextstrain/measles/legacy.zip/e1d1541c3ac44bc73da5872a2721d4edd10f9651") # <Response [200]>
-
https://github.com/<org>/<repo>/zipball/<commit>Example:
requests.get("https://github.com/nextstrain/measles/zipball/e1d1541c3ac44bc73da5872a2721d4edd10f9651") # <Response [200]>
-
https://github.com/<org>/<repo>/archive/<commit>.zipThis is the URL provided on the GitHub repo web page when clicking Code > Local > Download ZIP.
Example:
requests.get("https://github.com/nextstrain/measles/archive/e1d1541c3ac44bc73da5872a2721d4edd10f9651.zip") # <Response [200]>
-
Activity
jameshadfield commentedon Jun 29, 2025
[Posted on slack] I can't reproduce this -
nextstrain setup measles --forceworks fine for me running nextstrain-cli from 16630a1Note that
https://api.github.comis accessed directly from the server, almost certainly with GitHub credentials, multiple times (to work out versions, compatibility etc) before we get to the redirect. Since you see an error at the redirect stage I'd suspect this is due the redirect, when made from the CLI, being without credentials and running into a rate-limit or something.joverlee521 commentedon Jun 30, 2025
Hmm, I can't reproduce this either.
nextstrain setup measlesworked fine with Nextstrain CLI 10.2.0 (standalone) and latest dev version.victorlin commentedon Jun 30, 2025
Thanks for testing. I also can't reproduce on my personal computer at home. I'll continue debugging when I'm on my work laptop later and see if there's any more information in the Python response object.
On the surface, the 401 doesn't seem to be a rate limit, and GitHub docs back this up:
joverlee521 commentedon Jun 30, 2025
Ah yeah, I had previously run into the 403 rate limit error, but that shouldn't be as much of an issue now that we are going through the nextstrain.org API...
genehack commentedon Jun 30, 2025
Another "cannot reproduce" here.
Victor, have you tried from a different network? I wonder if some sort of automated process has you flagged as a bot or something…
victorlin commentedon Jun 30, 2025
Ahhh, it's due to a bad entry in my
~/.netrc:Not sure where it came from. The file was last modified on Sep 25 2024 and this is not the last entry, so it likely got added earlier than that. I'm using gh version 2.67.0 and it doesn't seem to do anything with
~/.netrc, but maybe once upon a timegh auth loginmanaged tokens in~/.netrc?I think the proper solution is not to make users delete entries in
~/.netrc, but instead ensure that the request is truly unauthenticated by ignoring it. This can be done by making the Python request withrequests.Session.trust_env = False.jameshadfield commentedon Jun 30, 2025
Out of interest, where is the request authenticated? The redirect URI is sent to the client (laptop) and then it's the client who makes the request. (Which is why this is the point it fails if you have a bad
.netrcor similar.) I ask because I don't know what our story is for private pathogen repos, or even if we have one.victorlin commentedon Jun 30, 2025
Oh, good to consider private repos. Currently this works with a valid netrc entry for
api.github.com:But I doubt the original intention was for this to work – we shouldn't expect users to touch netrc.
In other words and directly answering your question, I don't think the request is intended to be authenticated. It currently can be authenticated with an entry in netrc, but I consider that a bug.
victorlin commentedon Jun 30, 2025
Re: #445 (comment)
That would fix the bug without any other side effect, but I think we should take this opportunity to disallow setup of private repositories, at least via netrc. If we want to add support for private repositories, we should do so in another way that doesn't require modifying netrc.
genehack commentedon Jun 30, 2025
Fair enough, I guess.
Thinking about it, the Venn diagram intersection of "target audience for
nextstrain run" and "has a pathogen repo that requires authentication to download" is probably exceedingly thin.victorlin commentedon Jun 30, 2025
Getting sidetracked here 😄 but I think there is decent potential for usage along the lines of an external user forking our pathogen repo to edit Snakemake logic which can't be overridden by custom rules (or as a starting point for another pathogen not available through Nextstrain), needing to make the fork private due to organizational policy, and wanting colleagues to use it with
nextstrain run.tsibley commentedon Sep 3, 2025
FWIW, I disagree with the premise that we should disallow use of netrc. It's a longstanding way to provide static credentials for remote hosts, and it can be expected to work. That doesn't mean we shouldn't make the "invalid credentials in netrc" error path better, though.
This disables so much more than just reading of netrc, and it breaks documented functionality. We will need to revert it.
Revert "Ignore environment settings in pathogen repo request"
Hint at invalid credentials when handling 401/403 errors during patho…