4

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 4
    Looking at their [docs](https://pygithub.readthedocs.io/en/latest/introduction.html#very-short-tutorial) 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 – sedavidw May 18 '21 at 23:49
  • Thank you. I just needed to use my token. –  May 18 '21 at 23:59
  • @sedavidw You can add this as an answer, I'm pretty sure OP will check it for you. Am I right? – enzo May 19 '21 at 02:43
  • Copied to an answer – sedavidw May 19 '21 at 02:52

1 Answers1

4

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")
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
sedavidw
  • 11,116
  • 13
  • 61
  • 95
  • I am not Somalier, the API does allow username/password like GitHub(login_or_token=,passord=) according to https://pygithub.readthedocs.io/en/latest/github.html – eckes May 24 '21 at 16:45