On Thu, Sep 15, 2005 at 04:41:45PM +0200, Wido Depping wrote:
> Hi All,
> I've run accross a strange behaviour with simple_bind(). Instead of
> throwing exceptions when a bind wasn't succesful, it returns an
> integer. 4 for failure and 5 for success. Unfortunately I was assuming
> that this function would raise an exception. simple_bind_s() however
> behaves 'correctly'. Is this behaviour correct or a bug?
simple_bind is asynchronous, meaning that you need to take the number it
returns and pass it to result(). That's when it will raise the exception
>>> c.simple_bind('dc=okmaybe,dc=com', 'asdgfasfdg')
1
>>> c.result(1)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.4/site-packages/ldap/ldapobject.py", line 399,
in result
res_type,res_data,res_msgid = self.result2(msgid,all,timeout)
File "/usr/lib/python2.4/site-packages/ldap/ldapobject.py", line 405,
in result2
return self._ldap_call(self._l.result2,msgid,all,timeout)
File "/usr/lib/python2.4/site-packages/ldap/ldapobject.py", line 94,
in _ldap_call
result = func(*args,**kwargs)
ldap.INVALID_CREDENTIALS: {'info': '', 'desc': 'Invalid credentials'}
The reason it works with the _s version of the function is that all the
_s functions are synchronous, i.e. they are the same as calling
c.result(c.function(params...)). Depending on the way your app is
architected, either one may be apropriate.
-Mark
|