Authenticating against active directory using python + ldap
I was missing
l.set_option(ldap.OPT_REFERRALS, 0)
From the init.
That worked for me, l.set_option(ldap.OPT_REFERRALS, 0) was the key to access the ActiveDirectory. Moreover, I think that you should add an "con.unbind()" in order to close the connection before finishing the script.
If you are open to using pywin32, you can use Win32 calls from Python. This is what we do in our CherryPy web server:
import win32security
token = win32security.LogonUser(
username,
domain,
password,
win32security.LOGON32_LOGON_NETWORK,
win32security.LOGON32_PROVIDER_DEFAULT)
authenticated = bool(token)