我刚接触python,需要在LDAP中进行搜索,但是
当用户的CN和DisplayName不同时,我只能与
Domain\user连接。
见下文:
ldap3.Connection(s, user=user_cn, ....失败,ldap3.Connection(s, user=user_domain, ....接替>>> import ldap3
>>>
>>> ADDRESS = 'LDAP://192.168.26.10:389'
>>> user_cn = 'xxx test'
>>> user_domain = 'domain\xxx.test'
>>> password = 'password'
>>> s = ldap3.Server(ADDRESS, get_info=ldap3.ALL)
>>> c = ldap3.Connection(s, user=user_cn, password=password, auto_bind=True)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/ldap3/core/connection.py", line 325, in __init__
self.do_auto_bind()
File "/usr/local/lib/python3.5/dist-packages/ldap3/core/connection.py", line 353, in do_auto_bind
raise LDAPBindError(self.last_error)
ldap3.core.exceptions.LDAPBindError: automatic bind not successful - invalidCredentials
>>> c.extend.standard.who_am_i()
Traceback (most recent call last):
File "<console>", line 1, in <module>
NameError: name 'c' is not defined
>>>
>>> c = ldap3.Connection(s, user=user_domain, authentication = ldap3.NTLM,password=password, auto_bind=True)
>>> c.extend.standard.who_am_i()
'u:domain\\xxx.test'
>>>可以使用域/用户连接和绑定(),
但是当我进行搜索时,我仍然需要search_base中的CN。
问用户的域名和密码太麻烦了,有人能帮我吗?
谢谢!
ldap3 = 2.6
Python = 3.5.2
发布于 2020-02-13 11:53:26
您可以尝试使用以下内容来更改user=user_cn(user_domain):
user="{}\\{}".format("domain", username)
至少在我的版本中,这是我能够解决这个问题的方法:
conn1 = Connection(Server('LDAP://xxxxx.xxxx.xxxx.com:389'),
auto_bind=True,
user="{}\\{}".format("domain", username),
password=password)https://stackoverflow.com/questions/58907026
复制相似问题