无法使用 Ldap3 从 LDAP 中删除多个用户 Python

Unable to Delete Multiple users from LDAP with Ldap3 Python

我正在编写一个 python 脚本来删除一个 OU 下的所有用户。 ou=people,cn=AdministrativeLdap,cn=Windchill_11.0,o=ptc。

我正在尝试通过执行以下代码来删除条目,但失败并显示错误“无法删除,因为它有从属条目”,'referrals':None,'type' : 'delResponse'

有什么方法可以单独删除条目吗?

非常感谢!

from ldap3 import Server, Connection, ALL
s = Server('<IP-ADDRESS>', get_info=ALL)
print(s)
c = Connection(s, user='xxxxxx', password='xxxxxxxxxx')
c.bind() 
c.delete('ou=people,cn=AdministrativeLdap,cn=Windchill_11.0,o=ptc',force=True)
print(c.result)
c.unbind()

在 LDAP 中,您不能删除包含其他对象的“容器”对象。 DELETE 操作期望删除单个对象。您必须使用 delete() 删除每个对象。只有当容器对象不包含任何其他对象时,它才能被删除。

您也可以尝试使用 Subtree Delete Control 删除 LDAP 树的整个分支,但您必须检查您的 ldap 服务器是否支持它。