[python-ldap] Adding msgid to LDAPError

Michael Ströder michael at stroeder.com
Sat Sep 12 11:51:51 CEST 2015

Stephen J. Butler wrote:
> I've run into a situation where I issue a bunch of LDAPObject.search()
> requests and then loop while calling LDAPObject.result3() waiting for the
> responses. However, some of my search() requests will return a NO_SUCH_OBJECT
> error; and I'd like to just ignore that error and wait for the rest of the
> results.
> I can put the result3() in a try/except block, but when the exception happens
> I won't know which messageID it belongs to. So in a loop like this...
> while active_msgids:
>     try:
>         res_type, res_data, res_msgid, res_sctrls =
> conn.result3(self.result3(msgid=RES_ANY, all=0))
>     except LDAPError as ldapErr:
>         pass
>     else:
>         # Process successful result
>         active_msgids.remove(res_msgid)
> ... the error msgid never gets removed from active_msgids, and I end up
> looping forever.
> Attached is a patch that adds "msgid" to LDAPError where it makes sense, which
> is only for the result() set of methods.

Thanks for the patch. I will review more carefully later.

But just a quick question: Why not attach the msgid to also LDAPError
instances caused by write operations? Note that LDAP allows pipe-lining of
requests. You can send several write operations and deal with the result code
later. Your patch would be handy for those situations either.

While you're at it you could also attach the response controls (plural!)
returned by the server in the LDAPResult messages to the LDAPError instance.

This would e.g. solve the case of a simple bind failing because of an expired
password. Up to now the response control saying "password expired" cannot be
Also OpenLDAP's experimental "What failed?" control would require this for
determining what went wrong when using slapo-constraint, slapo-unique...

Ciao, Michael.

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

More information about the python-ldap mailing list