Skip to content

nextstrain setup <pathogen> not working #444

Closed

Description

@victorlin

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

  1. Ensure the Python request is unauthenticated by setting requests.Session.trust_env = False. (ref)
  2. ⛔️ Catch exceptions and if status=401 re-try with trust_env=False. (ref)
  3. ⛔️ Update the nextstrain.org endpoint to redirect to another URL. I found at least 3 alternatives that work.
    1. 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]>
    2. https://github.com/<org>/<repo>/zipball/<commit>

      Source: StackOverflow

      Example:

      requests.get("https://github.com/nextstrain/measles/zipball/e1d1541c3ac44bc73da5872a2721d4edd10f9651")
      # <Response [200]>
    3. https://github.com/<org>/<repo>/archive/<commit>.zip

      This 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

  1. added
    bug
    on Jun 27, 2025
  2. self-assigned this
    on Jun 28, 2025
  3. jameshadfield commented on Jun 29, 2025

    @jameshadfield
    Member

    [Posted on slack] I can't reproduce this - nextstrain setup measles --force works fine for me running nextstrain-cli from 16630a1

    Update the nextstrain.org endpoint to redirect to another URL.

    Note that https://api.github.com is 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.

  4. joverlee521 commented on Jun 30, 2025

    @joverlee521
    Contributor

    Hmm, I can't reproduce this either. nextstrain setup measles worked fine with Nextstrain CLI 10.2.0 (standalone) and latest dev version.

  5. victorlin commented on Jun 30, 2025

    @victorlin
    MemberAuthor

    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:

    If you exceed your primary rate limit, you will receive a 403 Forbidden or 429 Too Many Requests  response, and the x-ratelimit-remaining header will be 0. If you exceed a secondary rate limit, you will receive a 403 Forbidden or 429 Too Many Requests  response and an error message that indicates that you exceeded a secondary rate limit.

  6. joverlee521 commented on Jun 30, 2025

    @joverlee521
    Contributor

    On the surface, the 401 doesn't seem to be a rate limit, and GitHub docs back this up:

    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...

  7. genehack commented on Jun 30, 2025

    @genehack
    Contributor

    Hmm, I can't reproduce this either. nextstrain setup measles worked fine with Nextstrain CLI 10.2.0 (standalone) and latest dev version.

    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…

  8. victorlin commented on Jun 30, 2025

    @victorlin
    MemberAuthor

    Ahhh, it's due to a bad entry in my ~/.netrc:

    machine api.github.com
      login victorlin
      password ghp_************************************
    

    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 time gh auth login managed 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 with requests.Session.trust_env = False.

  9. jameshadfield commented on Jun 30, 2025

    @jameshadfield
    Member

    I think the proper solution is not to make users delete entries in ~/.netrc, but instead ensure that the request is truly authenticated by ignoring it. This can be done by making the Python request with requests.Session.trust_env = False.

    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 .netrc or similar.) I ask because I don't know what our story is for private pathogen repos, or even if we have one.

  10. victorlin commented on Jun 30, 2025

    @victorlin
    MemberAuthor

    Oh, good to consider private repos. Currently this works with a valid netrc entry for api.github.com:

    nextstrain setup flu-geo-fitness@main=https://api.github.com/repos/blab/flu-geo-fitness/zipball/5c5d4830412e18eeeb93217033668f8a0a2a7472
    

    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.

  11. victorlin commented on Jun 30, 2025

    @victorlin
    MemberAuthor

    Re: #445 (comment)

    [@victorlin] Previous behavior allowed setup of private repositories using the fully-specified <name>@<version>=<url> format

    [@genehack] I wonder if we could have our cake and eat it too using a "catch exceptions and if status=401 re-try with trust_env=False" strategy? Or is there not enough juice there for the squeeze that would be involved?

    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.

  12. genehack commented on Jun 30, 2025

    @genehack
    Contributor

    I think we should take this opportunity to disallow setup of private repositories, at least via netrc.

    Fair enough, I guess.

    If we want to add support for private repositories, we should do so in another way that doesn't require modifying netrc.

    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.

  13. victorlin commented on Jun 30, 2025

    @victorlin
    MemberAuthor

    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.

    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.

  14. tsibley commented on Sep 3, 2025

    @tsibley
    Contributor

    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 can be done by making the Python request with requests.Session.trust_env = False.

    This disables so much more than just reading of netrc, and it breaks documented functionality. We will need to revert it.

  15. self-assigned this
    on Sep 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions