executablebooks / github-activity

Simple markdown changelogs for GitHub repositories
https://github-activity.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
49 stars 11 forks source link

401 error no matter what kinda auth I try to use #96

Closed yuvipanda closed 3 months ago

yuvipanda commented 3 months ago

I've tried both classic and new PATs, as well as gh auth login.

github-activity -t https://github.com/jupyterhub/oauthenticator --since 16.3.0

fails with:

Using GH access token stored in `GITHUB_ACCESS_TOKEN`.
Running search query:
repo:jupyterhub/oauthenticator

Traceback (most recent call last):
  File "/Users/yuvipanda/.local/share/virtualenvs/oauthenticator/bin/github-activity", line 8, in <module>
    sys.exit(main())
  File "/Users/yuvipanda/.local/share/virtualenvs/oauthenticator/lib/python3.10/site-packages/github_activity/cli.py", line 176, in main
    md = generate_activity_md(
  File "/Users/yuvipanda/.local/share/virtualenvs/oauthenticator/lib/python3.10/site-packages/github_activity/github_activity.py", line 376, in generate_activity_md
    data = get_activity(
  File "/Users/yuvipanda/.local/share/virtualenvs/oauthenticator/lib/python3.10/site-packages/github_activity/github_activity.py", line 164, in get_activity
    qu.request()
  File "/Users/yuvipanda/.local/share/virtualenvs/oauthenticator/lib/python3.10/site-packages/github_activity/graphql.py", line 146, in request
    raise Exception(
Exception: Query failed to run by returning code of 401. {
  search(first: 50, query: "repo:jupyterhub/oauthenticator created:2000-03-16T00:00:00Z..2024-06-11T22:50:04Z", type: ISSUE) {
    issueCount
    pageInfo {
        endCursor
        hasNextPage
    }
    nodes {
      ... on PullRequest {
                state
        id
        title
        url
        createdAt
        updatedAt
        closedAt
        labels(first: 10) {
            edges {
                node {
                    name
                }
            }
        }
        number
        authorAssociation
        author {
          login
        }
        reactions(content: THUMBS_UP) {
          totalCount
        }

        mergedBy {
          login
        }
        mergeCommit {
          oid
        }
        baseRefName
                comments(last: 100) {
          edges {
            node {
              authorAssociation
              createdAt
              updatedAt
              url
              author {
                login
              }
            }
          }
        }

      }
      ... on Issue {
                state
        id
        title
        url
        createdAt
        updatedAt
        closedAt
        labels(first: 10) {
            edges {
                node {
                    name
                }
            }
        }
        number
        authorAssociation
        author {
          login
        }
        reactions(content: THUMBS_UP) {
          totalCount
        }

                comments(last: 100) {
          edges {
            node {
              authorAssociation
              createdAt
              updatedAt
              url
              author {
                login
              }
            }
          }
        }

      }
    }
  }
}
minrk commented 3 months ago

97 fixes an encoding problem when github-activity tries to get the token from gh itself, which would look like this if you didn't specify GITHUB_ACCESS_TOKEN, but it looks like you did.

FWIW, I've been using:

 export GITHUB_ACCESS_TOKEN=$(gh auth token)
github-activity

If that doesn't work, does gh have a valid token? (check with gh api /user).

If the token is valid and you can use it in curl:

curl -H "Authorization: Bearer ${GITHUB_ACCESS_TOKEN}" https://api.github.com/user

then you might be hitting requests' weird netrc handling. Do you have anything for api.github.com in your .netrc?

minrk commented 3 months ago

was auto-closed because of a magic string in #97, but would be good to confirm from @yuvipanda first

yuvipanda commented 3 months ago

Unfortunately the issue persists :( I even fully uninstalled gh to no avail

yuvipanda commented 3 months ago

I installed from main with pip install --force -U git+https://github.com/executablebooks/github-activity@main

yuvipanda commented 3 months ago

curl -H "Accept: application/vnd.github+json" -H "Authorization: Bearer $(gh auth token)" "https://api.github.com/search/issues?q=repo:jupyterhub/jupyter-server-proxy+created:2000-04-02T00:00:00Z..2024-06-12T20:58:22Z"

works. It's the same search query that github-activity is trying to use and failing

minrk commented 3 months ago

Do you have a .netrc file, and does it have api.github.com in it?

yuvipanda commented 3 months ago
image

WELL WOULD YOU LOOK AT THAT :)

Good psychic debugging, @minrk!

I think it would be useful for the app to print 'using netrc credentials' or similar maybe, as currently netrc seems to override what's even explicitly passed

minrk commented 3 months ago

Not psychic, personal history! I've been flummoxed by this requests behavior a number of times over the years.

Also, I don't think it's easy for us to detect this because the netrc credentals are loaded deep within requests, so I'm not sure we can warn about it very well. It can be disabled, but not without turning off a bunch of unrelated settings like proxy env, etc. Maybe it's best to disable those, since we aren't likely to use them.