title: How to create a ldap test server with python?
body: <p>I want to create a ldap test server with python and import all data with a ldif file.</p>
  <pre><code>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&quot;ldap://{server.hostname}&quot;)
      connect.set_option(ldap.OPT_REFERRALS, 0)
      connect.simple_bind_s(root_dn, root_pw)
  
      result = connect.search_s(...)
  </code></pre>
  <p>But I have the problem, that I get the error message that the ldap server is down (<code>ldap.SERVER_DOWN: {'result': -1, 'desc': &quot;Can't contact LDAP server&quot;, 'errno': 107, 'ctrls': [], 'info': 'Transport endpoint is not connected'}</code>).</p>