繁体   English   中英

LDAP 过滤器与 ldap3 库不工作

[英]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'

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

好的,找到了解决方案。 必须像这样在连接中提供凭据:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM