【发布时间】:2012-11-29 22:43:07
【问题描述】:
python-ldap newb 在这里。我正在尝试使用以下示例代码来做到这一点:
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
我收到各种错误:
使用虚拟机的 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 :
{'desc': "Can't contact LDAP server"}
{'desc': "Can't contact LDAP server"}
我查看了以下 S.O.没有分辨率的帖子:
【问题讨论】:
标签: python active-directory ldap python-ldap