How to create a ldap test server with python?

3.3k views Asked by At

I want to create a ldap test server with python and import all data with a ldif file.

import ldap
import slapdtest

with slapdtest.SlapdObject() as server:

    server.start()

    with open('ldap_dump.ldif') as fd:
        server.ldapadd(fd.read(), ['-D', 'cn=User,dc=institute.edu'])

    root_dn = server.root_dn
    root_pw = server.root_pw

    connect = ldap.initialize(f"ldap://{server.hostname}")
    connect.set_option(ldap.OPT_REFERRALS, 0)
    connect.simple_bind_s(root_dn, root_pw)

    result = connect.search_s(...)

But I have the problem, that I get the error message that the ldap server is down (ldap.SERVER_DOWN: {'result': -1, 'desc': "Can't contact LDAP server", 'errno': 107, 'ctrls': [], 'info': 'Transport endpoint is not connected'}).

0

There are 0 answers