【发布时间】:2021-02-22 14:56:34
【问题描述】:
我有一个 LDAP 查询,它在我的终端中运行良好
ldapsearch -h ldap.mygreatcompany.com -D user@mygreatcompany.COM -w "$ldappassword" -b "DC=abc,DC=mygreatcompany,DC=com" -s sub "(mail=user1@mygreatcompany.COM)" sAMAccountName
我想在 python3 中运行这个命令,我按照 StackOverflow 的其他答案写了这样的东西,
import ldap
l = ldap.initialize('ldap://ldap.mygreatcompany.com')
binddn = "user@mygreatcompany.COM"
pw = #ldappassword
basedn = "DC=abc,DC=mygreatcompany,DC=com"
searchAttribute = ["sAMAccountName"]
searchFilter = "(&(mail=user1@mygreatcompany.COM')(objectClass=*))"
searchScope = ldap.SCOPE_SUBTREE
l.simple_bind_s(binddn, pw)
ldap_result_id = l.search_s(basedn, searchScope, searchFilter, searchAttribute)
#Get result
l.unbind_s()
但是在这里我没有从 ldap_result_id 得到结果。任何人都可以帮助执行此查询的正确方法是什么?
谢谢
【问题讨论】:
-
我不知道这是否是一个错字,但看起来变量
searchScope没有在您的代码中定义,如果您将范围设置为l.search_s(basedn, ldap.SCOPE_SUBTREE, ...)会发生什么? -
@EricLavault,抱歉打错了。我更新了。
标签: python-3.x ldap ldap-query python-ldap ldap3