Reputation: 1937
I am using below code to test ldap connection but its getting failed with 'info': 'Invalid DN syntax', 'desc': 'Invalid DN syntax'}.
import ldap
AD_LDAP_URL = 'ldap://test.example.com'
username = 'User'
password = 'PassWord'
try:
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
l = ldap.initialize(AD_LDAP_URL)
l.simple_bind_s(username, password)
except ldap.NO_SUCH_OBJECT, e:
print "Auth error: No user "
except ldap.INVALID_CREDENTIALS, e:
print 'error'
except ldap.LDAPError, e:
print e
Upvotes: 3
Views: 1761
Reputation: 774
This happens because you should send DN of the user to bind method (or simple_bind_s), not just the username. A example of valid DN - cn=user,dc=example,dc=com
P.S. You can use some tools for easier navigation in your LDAP (for example jXplorer allows to copy DN of an object).
Upvotes: 2