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
我收到各种错误:
使用虚拟机的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'}
使用本地主机或 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:
Python-ldap 身份验证Python-ldap 微软
推荐答案
根据 文档,ldap.open 已弃用.您应该尝试 ldap.initialize,就像您提供的两个链接一样.另外,请确保您的专有名称中没有空格:"cn=administrator, o=joe.local".
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:连接和删除用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:python-ldap 和 Microsoft Active Directory:连接和删除用户
基础教程推荐
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
