[python-ldap] Adding msgid to LDAPError

Stephen J. Butler stephen.butler at gmail.com
Sat Sep 12 11:34:18 CEST 2015


Hello,

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. Link in case it gets
stripped: <https://uofi.box.com/s/nrhxqu1o3y37pjnbu5hkqopkfal1egfc>. It
lets me write code 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:
        try:
            err_msgid = ldapErr.message['msgid']
        except:
            raise ldapErr
        else:
            active_args.remove(err_msgid)
    else:
        # Process successful result
        active_msgids.remove(res_msgid)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20150912/e82e01af/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: python-ldap-errmsgid.patch
Type: application/octet-stream
Size: 20337 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20150912/e82e01af/attachment-0001.obj>


More information about the python-ldap mailing list