I have now managed to establish a connection, but now only False and an empty list come out. I have cut the search_base. This is my first time working with ldap.
ldap.py:
import ldap3
from ldap3 import Server, Connection, ALL
s = 'ldap://...int'
user = 'Y'
password = '1234'
server = Server(s, get_info = ALL)
conn = Connection(server,user,password)
print(conn.bind())
result = conn.search(search_base='ou=...,dc=...,dc=...,dc=...,', search_filter='(initials=user)')
print(result)
print(conn.entries)
Output:
False
False
[]
Import LDAPBindError and wrap your bind attempt in a try/except. You should then get some indication if your connection or bind attempt aren't working (e.g. "ldap3.core.exceptions.LDAPSocketOpenError: invalid server address" if the directory server hostname is bad).
import ldap3
from ldap3 import Server, Connection, ALL
from ldap3.core.exceptions import LDAPBindError
server = Server('ldap://directoryserver.example.com', get_info = ALL)
con = Connection(server,'MyUser@example.com','P2s%w0rd')
try:
con.bind()
except LDAPBindError:
print(con.result)
Thank you. He has now established a connection because I have now found out that my user was wrong.