带有 ldap3 库的 LDAP 过滤器不起作用

LDAP filter with ldap3 library not working

我正在尝试使用以下 Python 代码片段从 LDAP 中检索用户的信息。 我正在使用 ldap3 库查询 LDAP。

def searchUser():
    server = Server('myLdapServer:389')
    try:
        with Connection(server) as conn:
            conn.search('ou=xuser,ou=xxx,o=com', '(attribute=cn=user,ou=yuser,ou=xxx,o=com)', attributes=['*'])
            for entry in connection.entries:
                print(entry)
    except:
        return 'error in ldap search'

不幸的是,即使当我在 Softerra Ldap-Browser 中输入 Ldap-Base 和 Ldap-Filter 时,我也没有得到任何结果。我在 Softerra-Browser 和代码中使用相同的 Ldap 用户。

确定找到解决方案。必须像这样在连接中提供凭据:

with ldap3.Connection(server, user="myLdapUser", password="myLdapPassword", auto_bind=True)