cannot import module Auth form Github by PyGitHub

867 Views Asked by At

I want to try PyGitHub a Python library to access the GitHub REST API.

python imterpreter: anaconda python 3.10

the first step, I install the command

pip install PyGithub

enter image description here

after that, I try to follow the tutorial to create a GitHub instance:

from github import Github
from github import Auth
auth = Auth.Token("access_token")
g = Github(auth=auth)
g = Github(auth=auth, base_url="https://{hostname}/api/v3")

This error message how to solve

from github import Auth
ImportError: cannot import name 'Auth' from 'github'
1

There are 1 best solutions below

0
akalanka On

Having the same problem with importing Auth.

The old approach still works, even though I have no idea which approach is better.

from github import Github

access_token = "your GH access token" 

gh = Github(access_token)

for repo in gh.get_user().get_repos():
    print(repo.name)

I put the access token as a string in the code for simplicity. In my actual code, I am using a config file to import the token.