0

我正在开发一个 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
4

1 回答 1

1

修复问题!我使用了错误的身份验证方法。我应该使用 login_as_app(private_key_pem=key_file_pem, app_id=app_id) 来使用 app_installations() 方法。

于 2020-06-15T17:24:21.443 回答