Hello everyone, please tell me how to properly consider the exceptions associated with errors when using the ldap3 module
from pprint import pprint from ldap3 import Connection, Server, NTLM, ALL, ALL_ATTRIBUTES def search(ip,bind_name, bind_pwd, search_base, search_filter, attrs=None): server = Server(f'ldap://{ip}', get_info=ALL) try: with Connection(server, bind_name, bind_pwd, auto_bind=True,) as conn: conn.search(search_base, search_filter, attributes=attrs) out = conn.entries return out except ldap3.core.exceptions as err: pprint (err) throws an error builtins.NameError: name 'ldap3' is not defined
ldap3.core.exceptions, because you did import from ldap3, and not import it, so the identifier ldap3 does not exist - gil9redimport ldap3- gil9redimport ldap3except ldap3.core.exceptions.LDAPBindError as err:works, I can not figure out how to determine the import, so as not to import the entire module, tell me? - Andreifrom ldap3.core.exceptions import LDAPBindError, thenexcept LDAPBindError as e- gil9red