Python 3.x 如何将ldap转换为ldap3 Python
我正在尝试连接到ldap服务器,以便flask应用程序可以验证active directory中的用户。当我使用LDAP时,身份验证和绑定工作得非常好。但是,当我使用flask登录时,它不会连接 这是我的工作代码:Python 3.x 如何将ldap转换为ldap3 Python,python-3.x,flask,ldap,flask-login,Python 3.x,Flask,Ldap,Flask Login,我正在尝试连接到ldap服务器,以便flask应用程序可以验证active directory中的用户。当我使用LDAP时,身份验证和绑定工作得非常好。但是,当我使用flask登录时,它不会连接 这是我的工作代码: import ldap import ldap3 from pprint import pprint user = 'my_username' password = 'my_password' search_base = 'my_path' Scope = ldap.SCOPE_S
import ldap
import ldap3
from pprint import pprint
user = 'my_username'
password = 'my_password'
search_base = 'my_path'
Scope = ldap.SCOPE_SUBTREE
search_filter = "(SamAccountName=my_value)"
Attrs = ["*"] # or None
conn = ldap.initialize("ldap://my_server")
conn.protocol_version = 3
conn.set_option(ldap.OPT_REFERRALS, 0)
conn.simple_bind_s(user, password)
results = conn.search_s(
search_base,
ldap.SCOPE_SUBTREE,
search_filter,
Attrs)
conn.unbind()
pprint(results)
当我使用相同的凭据但使用ldap3时,结果显示为空:
# Using ldap3
server = ldap3.Server('ldap://my_server')
with ldap3.Connection(server, auto_bind=False) as conn:
conn.search(search_base, search_filter, attributes=Attrs)
pprint(conn.entries)
关于发生这种情况的原因,您有什么想法或建议吗?在ldap示例中,您正在进行身份验证(
conn.simple\u bind(user,password)
),但在ldap3示例中您从未进行过身份验证。