[python-ldap] How do i know if bind was successful?

Michael Ströder michael at stroeder.com
Mon Apr 22 09:32:11 CEST 2013


Anurag Chourasia wrote:
> I am exploring python-ldap and I have the following question.
> 
> I am testing using ADAM on Windows XP.
> 
> How could i know if my bind request was successful.

After a successful simple bind operation the server returns a LDAP response
with error code ok (0) => no LDAPError exception raised.

Which authorization identity is in effect can be queried by LDAP Who Am I?
extended operation if the server supports it:

http://www.python-ldap.org/doc/html/ldap.html#ldap.LDAPObject.whoami_s

Not sure whether MS ADAM supports it though.

> This is my session transcript.
> 
>>>> import ldap
>>>> l=ldap.initialize('ldap://localhost:389')
>>>> who="CN=achourasia,OU=Appl
> Groups,OU=Central,OU=CL,DC=cencosud.corp,O=App,C=US"
>>>> cred="Jaisai1"
>>>> result=l.bind(who,cred)
>>>> l.result(result)
> (97, [])
>>>>
> 
> What is 97 above supposed to mean? When a exception is not thrown then does it
> mean that the request was successful?

Please read first about the difference of synchronous and asynchronous
operation methods:

http://www.python-ldap.org/doc/html/ldap.html#sending-ldap-requests

You probably want to use simple_bind_s():

http://www.python-ldap.org/doc/html/ldap.html#ldap.LDAPObject.simple_bind_s

bind_s() is nowadays just a thin wrapper around simple_bind_s().

Ciao, Michael.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3883 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20130422/394e4163/attachment-0001.bin>


More information about the python-ldap mailing list