I would like to know the difference between LDAP3 Connection(auto_bind=True) and Connection().bind() in Python

1k views Asked by At

I was passing wrong credentials(password) in below code

conn = Connection(server, account_username, account_password, auto_bind=True)

and getting below error

ldap3.core.exceptions.LDAPBindError: automatic bind not successful - invalidCredentials

When I do the same without auto_bind argument in connection.

conn = Connection(server, account_username, account_password)
conn.bind()

conn was not throwing any error. conn.bind() is False. Help would be appreciated. Thanks

1

There are 1 answers

0
Filip Poplewski On

There are two ways to accomplish this:

  1. Check error raised during the last bind in the connection.last_error field.
server = ldap3.Server("LDAP_HOST", use_ssl=True)
connection = ldap3.Connection(
    server,
    "WRONG_LDAP_USERNAME",
    "WRONG_LDAP_PASSWORD"
)
connection.bind()
print(connection.last_error)

result

invalidCredentials
  1. Set argument raise_exceptions=True during initialization of the ldap3.Conneciton
server = ldap3.Server("LDAP_HOST", use_ssl=True)
connection = ldap3.Connection(
    server,
    "WRONG_LDAP_USERNAME",
    "WRONG_LDAP_PASSWORD",
    raise_exceptions=True
)
connection.bind()

result

dap3.core.exceptions.LDAPInvalidCredentialsResult: LDAPInvalidCredentialsResult - 49 - invalidCredentials - None - None - bindResponse - None