首页 > 解决方案 > 无法使用 python ldap3 模块连接到 ldap

问题描述

我正在使用在线 LDAP 测试服务器(https://www.forumsys.com/tutorials/integration-how-to/ldap/online-ldap-test-server/

我正在尝试使用 python ldap3 模块连接到它。

这是我的代码:

import ldap3
user = 'riemann'
password = 'password'
server = ldap3.Server('ldap.forumsys.com', port=389)
connection = ldap3.Connection(server, user=user, password=password)
connection.bind()
conn = connection.search(search_base='ou=mathematicians,dc=example,dc=com', search_filter='(&(objectClass=user)(userPrincipalName='+user+'))', attributes='*')

print conn

当我检查 conn 时,它是False

有人可以帮助我获得连接提前谢谢

标签: pythonldapopenldappython-ldapldap3

解决方案


如果您更改user='riemann'为,user='uid=riemann,dc=example,dc=com'您将获得连接

有关更多信息,请查看文档: http: //ldap3.readthedocs.io/bind.html#simple-bind


推荐阅读