python-ldap和Microsoft Active Directory:连接并删除用户 [英] python-ldap and Microsoft Active Directory: connect and delete user
本文介绍了python-ldap和Microsoft Active Directory:连接并删除用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
python-ldap newb在这里.我正在尝试使用以下示例代码进行此操作:
python-ldap newb here. I am trying to do this with the following sample code:
import ldap
## first you must bind so we're doing a simple bind first
try:
l = ldap.open("valid ip")
l.set_option(ldap.OPT_REFERRALS, 0)
l.protocol_version = ldap.VERSION3
# Pass in a valid username and password to get
# privileged directory access.
# If you leave them as empty strings or pass an invalid value
# you will still bind to the server but with limited privileges.
username = "cn=administrator, o=joe.local"
password = "password"
# Any errors will throw an ldap.LDAPError exception
# or related exception so you can ignore the result
l.simple_bind(username, password)
except ldap.LDAPError, e:
print e
# handle error however you like
# The next lines will also need to be changed to support your requirements and directory
deleteDN = "uid=hihihi, ou=LoginUsers,o=joe.local"
try:
# you can safely ignore the results returned as an exception
# will be raised if the delete doesn't work.
l.delete_s(deleteDN)
except ldap.LDAPError, e:
print e
## handle error however you like
我遇到各种错误:
使用VM的IP:
{'info': '000004DC: LdapErr: DSID-0C0909A2, comment: In order to perform this op
eration a successful bind must be completed on the connection., data 0, v1db1',
'desc': 'Operations error'}
使用localhost或127.0.0.1:
Using localhost or 127.0.0.1 :
{'desc': "Can't contact LDAP server"}
{'desc': "Can't contact LDAP server"}
我看了下面的S.O.没有解决方法的帖子:
I have looked at the following S.O. posts with no resolution:
推荐答案
根据.
According to the documentation, ldap.open
is deprecated. You should try ldap.initialize
, like the two links you provided. Also, make sure there are no spaces in your distinguished names: "cn=administrator, o=joe.local"
.
如果这不能解决问题,请确保提及该错误来自哪一行.
If that doesn't fix the problem, then make sure to mention which line that error is coming from.
这篇关于python-ldap和Microsoft Active Directory:连接并删除用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文