2

我正在使用 Github3 库来访问 Github Enterprise API。我正在尝试获取特定用户拥有的所有组织,但是在获得 ShortOrganization 的生成器之后,我不知道如何实际获取组织名称,有人可以帮忙吗?

这是我的尝试:

ghe = github3.enterprise_login(url=url, token=access_token)
user = ghe.user('myu')
iter_org = user.organizations()
print(iter_org)
org_list = []
for org_name in iter_org:
    org_list.append(org_name.login)
print(org_list)

以下是我当前的输出:

<GitHubIterator [-1, /api/v3/users/myu/orgs]>
 []

我哪里做错了?

4

1 回答 1

1

.organizations() 调用需要经过身份验证的用户。当你这样做

用户 = ghe.user('myu')

你只是得到用户。为了验证用户身份然后获取所有组织,我尝试了以下方法并且它正在工作:

from github3 import login

gh = login('username', password='password')
organizations = gh.organizations()

for org in organizations:
    org = org.refresh()
    print(org.login)
于 2018-08-01T03:00:10.167 回答