我正在尝试使用ldap3版本“0.9.7.4”将一些代码更新为python3。 (https://pypi.python.org/pypi/ldap3)
以前,我使用python ldap和python2来验证这样的用户:
import ldap
address = "ldap://HOST:389"
con = ldap.initialize(address)
base_dn = "ourDN=jjj"
con.protocol_version = ldap.VERSION3
search_filter = "(uid=USERNAME)"
result = con.search_s(base_dn, ldap.SCOPE_SUBTREE, search_filter, None)
user_dn = result[0][0] # get the user DN
con.simple_bind_s(user_dn, "PASSWORD")
这将正确返回正确密码的(97, [], 2, [])
,并在使用错误密码的绑定尝试时引发ldap.INVALID_CREDENTIALS
。
在python3中使用ldap3
我正在执行以下操作:
from ldap3 import Server, Connection, AUTH_SIMPLE, STRATEGY_SYNC, ALL
s = Server(HOST, port=389, get_info=ALL)
c = Connection(s, authentication=AUTH_SIMPLE, user=user_dn, password=PASSWORD, check_names=True, lazy=False, client_strategy=STRATEGY_SYNC, raise_exceptions=True)
c.open()
c.bind()
它引发了以下异常:
ldap3.core.exceptions.LDAPInvalidCredentialsResult: LDAPInvalidCredentialsResult - 49 - invalidCredentials - [{'dn': '', 'message': '', 'type': 'bindResponse', 'result': 0, 'saslCreds': 'None', 'description': 'success', 'referrals': None}]
我正在使用python2的ldap搜索返回的user_dn
值,因为这似乎在python2中起作用。
在python3中如何使用ldap3使其正确绑定?
(有一件事很奇怪,我注意到,ldap3的LDAPInvalidCredentialsResult包含'description': 'success'
。我猜这只是意味着成功地收到了回应。。。)
我是ldap3的作者,请在连接定义中设置
raise_exceptions=False
,并在绑定后检查connection.result
。你应该知道你的bind()
不成功的原因。相关问题 更多 >
编程相关推荐