簡體   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