Python Connect LDAP Server Test




    The code segment gets a connection to an LDAP server. If no DN is given, the program tries to get a connection to the server using the current user's DN. If the given DN is not a valid LDAP directory node, an error is generated and the program ends.

    from ldap3 import Server, Connection, ALL
    def get_ldap_connection(dn=None, password=None, LDAP_URI=None):
        server = Server(LDAP_URI, get_info=ALL)
        conn = Connection(server, dn, password)
        if not conn.bind():
            print("Connon bind to ldap server")
            print("bind to ldap server success")
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.