我是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
谁知道我的错误在哪里?还是解释一下我是否错误使用了该功能?
答案 0 :(得分:0)
您需要先获取用户,然后在 has_in_members 和 remove_from_members 内部传递用户对象。
user = g.get_user('myu')
mem_exist = org.has_in_members(user)
if mem_exist:
org.remove_from_members(user)