5

I was trying to figure out how to use the PyGithub module, but I keep getting the same error:

github.GithubException.GithubException: 401 {"message": "Requires authentication", "documentation_url": "https://docs.github.com/rest/reference/users#get-the-authenticated-user"}

My code is pretty simple, considering I just started out:

from github import Github
g = Github("Charonum","xxxxxxxx")
user = g.get_user()
print(user.name)
print(user.login)

The error is when it gets to print(user.name).

4
  • 4
    Looking at their docs it doesn't look like you're initializing the Github class correctly. I would read through that to find more about how to properly setup. The error is pretty clear that you don't have your auth credentials input properly Commented May 18, 2021 at 23:49
  • Thank you. I just needed to use my token. Commented May 18, 2021 at 23:59
  • @sedavidw You can add this as an answer, I'm pretty sure OP will check it for you. Am I right? Commented May 19, 2021 at 2:43
  • Copied to an answer Commented May 19, 2021 at 2:52

1 Answer 1

5

Looking at their documentation, it doesn't look like you're initializing the Github class correctly. I would read through that to find more about how to properly setup. The error is pretty clear that you don't have your authentication credentials input properly.

Example from the documentation:

from github import Github

# using an access token
g = Github("access_token")

# Github Enterprise with custom hostname
g = Github(base_url="https://{hostname}/api/v3", login_or_token="access_token")
Sign up to request clarification or add additional context in comments.

1 Comment

I am not Somalier, the API does allow username/password like GitHub(login_or_token=,passord=) according to pygithub.readthedocs.io/en/latest/github.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.