首页 > 解决方案 > pygithub - 如何创建检查运行?

问题描述

我正在尝试在 github 中创建一个检查运行(参考:)

import jwt
import time
from github import Github

pem_file = "ci-results.2020-11-27.private-key.pem"
installation_id = 13221707
app_id = 90466

time_since_epoch_in_seconds = int(time.time())
payload = {
    # issued at time
    'iat': time_since_epoch_in_seconds,
    # JWT expiration time (10 minute maximum)
    'exp': time_since_epoch_in_seconds + (5 * 60),
    # GitHub App's identifier
    'iss': app_id
}

this_jwt = jwt.encode(payload, open(pem_file, 'r').read().strip().encode(), 'RS256').decode()

gh = Github(jwt=this_jwt)

gh.get_app("ci-results")

# installation = gh.get_installation(installation_id)

# for repo in (installation.get_repos()):
#     print (repo)

我收到以下错误:

github.GithubException.BadCredentialsException: 401 {"message": "Bad credentials", "documentation_url": "https://docs.github.com/rest"}

我通过直接在 REST API 中使用来检查创建的 JWT 是否正确。我认为我没有正确使用 pyGitHUb 进行 JWT 身份验证,知道我做错了什么吗?

标签: pygithub

解决方案


推荐阅读