我有以下代碼Python的LDAP3重新綁定方法不會引發錯誤
from ldap3 import Server, Connection, SUBTREE, ALL_ATTRIBUTES, LDAPBindError
...
...
def search(self, id):
if not self._connect.bind():
print('error in bind', self._connect.result)
else:
self._connect.search(
search_base=self._base_dn,
search_filter='(uid='+id+')',
search_scope=SUBTREE
)
userdn = self._connect.response[0]['dn']
try:
self._connect.rebind(user=userdn, password='password')
print(self._connect.result)
except LDAPBindError:
print('error in rebind', self._connect.result)
self._connect.unbind()
pass
根據python-ldap3
文檔rebind
方法應該拋出一個LDAPBindError
文檔:
# import class and constants
from ldap3 import Server, Connection, ALL, LDAPBindError
# define the server
s = Server('servername', get_info=ALL) # define an unsecure LDAP server, requesting info on DSE and schema
# define the connection
c = Connection(s, user='user_dn', password='user_password')
# perform the Bind operation
if not c.bind():
print('error in bind', c.result)
try:
c.rebind(user='different_user_dn', password='different_user_password')
except LDAPBindError:
print('error in rebind', c.result)
如果證書無效或者服務器不允許您重新綁定證書rver可能會突然關閉連接。這個條件是由rebind()方法檢查的,如果是caugh,將會引發一個LDAPBindError異常。 Link to this
的問題是,雖然一切似乎運作良好,我可以確認,從打印result
財產。
在succeful重新綁定: {'result': 0, 'description': 'success', 'type': 'bindResponse', 'message': '', 'dn': '', 'referrals': None, 'saslCreds': None}
在失敗重新綁定: {'type': 'bindResponse', 'dn': '', 'result': 49, 'description': 'invalidCredentials', 'message': '', 'referrals': None, 'saslCreds': None}
雖然未能重新綁定引發任何異常。我有沒有理解錯誤,不應該提出錯誤?否則爲什麼它不,我有錯?
感謝您的任何幫助。