0

我是 Python 和 Github API 的新手,目前正在尝试使用 Pygithub 访问 Github 企业 API。目标是查找特定成员是否在组织中。如果是这样,请将其从组织中删除。我的当前代码如下:

access_token = "my_ghe_org_token"
g = Github(base_url="https://{my_ghe_hostname}/api/v3", login_or_token=access_token)
org = g.get_organization('my_org_name')
mem_exist = org.has_in_members('myu')
if mem_exist:
    org.remove_from_members('myu')

它给出以下错误:

    Traceback (most recent call last):
  File "disable_ghe.py", line 21, in <module>
    disable_ghe()
  File "disable_ghe.py", line 9, in disable_ghe
    mem_exist = org.has_in_members('myu')
  File "/Users/myu/Desktop/github/venv/lib/python3.6/site-packages/github/Organization.py", line 769, in has_in_members
    assert isinstance(member, github.NamedUser.NamedUser), member

有人知道我的错误在哪里吗?或者如果我错误地使用了该功能,请解释一下?

我正在尝试打这个电话: http: //pygithub.readthedocs.io/en/stable/github_objects/Organization.html#github.Organization.Organization.has_in_members

4

1 回答 1

0

您需要先获取用户,然后在has_in_membersremove_from_members 中传递用户对象。

user = g.get_user('myu')
mem_exist = org.has_in_members(user)

if mem_exist:
    org.remove_from_members(user)
于 2018-07-30T23:23:33.680 回答