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

Anurag Chourasia anurag.chourasia at gmail.com
Mon Apr 22 10:22:06 CEST 2013


Hi Michael,

Thanks for your response.

Please note that if i supply a wrong password then the bind step gives me
an error *ldap.INVALID_CREDENTIALS*

With the correct password it does not throw any exception as such....

If i use Apache Directory Studio instead of MS ADAM for my tests then the
Search function works fine despite the bind having given the same results
as in my original problem transcript.

Here is a session transcript with Apache Server Studio

>>> import ldap
>>> l=ldap.initialize('ldap://127.0.0.1:10389')
>>> who="uid=admin,ou=system"
>>> cred="123456"
>>> result=l.bind(who,cred)
>>> l.result(result)
(97, [])
>>> l.search_s('OU=Appl Groups,OU=Central,OU=CL,DC=cen,DC=corp', 0,
'(objectClass=*)')
[('OU=Appl Groups,OU=Central,OU=CL,DC=cencosud,DC=corp', {'objectClass':
['organizationalUnit', 'top'], 'ou': ['Appl Groups']})]

Regards,
Anurag

On Mon, Apr 22, 2013 at 3:32 AM, Michael Ströder <michael at stroeder.com>wrote:

> 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 --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20130422/96d9bb1f/attachment.html>


More information about the python-ldap mailing list