Parthasarathy J
Parthasarathy J

Reputation: 17

Unable to Delete Multiple users from LDAP with Ldap3 Python

I am writing a python script that deletes all the users under an OU. ou=people,cn=AdministrativeLdap,cn=Windchill_11.0,o=ptc.

I am trying to delete the entries by performing the following code but it fails with error " cannot be removed because it has subordinate entries", 'referrals': None, 'type': 'delResponse"

Is there a way by which I can remove the entries alone?

Thank you so much!

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()

Upvotes: 1

Views: 1458

Answers (1)

cannatag
cannatag

Reputation: 1598

In LDAP you can’t delete a “container” object if it contains other object. The DELETE operation expect a single object to delete. You have to remove each object with delete(). Only when the container object doesn’t contain any other object it can be removed.

You can also try the Subtree Delete Control that lets you remove a whole branch of the LDAP tree, but you must check if your ldap server supports it.

Upvotes: 1

Related Questions