我正在开发一个github应用程序,我的实际任务是检索安装了该应用程序的github用户帐户/github组织的列表。因此,基本上,我将使用Github3.py库中的app_installations()方法。此方法需要身份验证。因此,通过运行以下代码:
def get_users():
user = "bilel.e***********"
password = "5QPN74dHD******"
gh = login(user, password)
#gh is an instance of <class 'github3.github.GitHub'>
scopes = ['user', 'repo']
auth = gh.authorize(user, password, scopes)
ghi = gh.app_installations()
return ()
get_users()
我收到以下输出:
Traceback (most recent call last):
File "ghe-admin-app/service.py", line 33, in <module>
get_users()
File "ghe-admin-app/service.py", line 29, in get_users
auth = gh.authorize(user, password, scopes)
File "/usr/local/lib/python3.7/dist-packages/github3/github.py", line 503, in authorize
json = self._json(self._post(url, data=data), 201)
File "/usr/local/lib/python3.7/dist-packages/github3/models.py", line 156, in _json
raise exceptions.error_for(response)
github3.exceptions.UnprocessableEntity: 422 Validation Failed
我应该提到的是,我故意尝试输入错误的密码,结果不出所料:
github3.exceptions.AuthenticationFailed: 401 Bad credentials
已修复问题!我使用了错误的身份验证方法。我应该使用login_as_app(private_key_pem=key_file_pem,app_id=app_id)来使用app_installations()方法。