[python-ldap] Searching with paged results?

John john+python_org at daaave.org
Wed Feb 10 17:44:17 EST 2021


  I can't seem to get paged results working with a search; I think I did manage to partially get it, 'cause I set the paging to 1,000 results and I got 1,000 results back (out of a total of ~800K), but I'm stuck and all the stuff I can find online is either for the 2.x version of this package, or the "ldap3" package.

  In any case, what I would like is to run a search like this:

----- 8< 8< 8< -----
result = self.directory_connection.search_ext_s(
    base_dn,
    scope,  
    filterstr = search_filter,
    attrlist  = attributes,
    sizelimit = size_limit,
    timeout   = time_limit,
)

for dn, entry in result:
    ## do stuff
----- >8 >8 >8 -----

...and get _all_ the results, using paged search to work with the LDAP server's resource limits.

  Basically, I want to reproduce the behaviour of "ldapsearch -E pr=10000/noprompt", which does work against this server to return the entire result set.

  This is what I have now, that only gives me 1,000 results (out of ~800K):

----- 8< 8< 8< -----
ldap_controls = ldap.controls.libldap.SimplePagedResultsControl(
    #criticality = False,
    size = 1000, 
    cookie = b'',
)

## Release the hounds! 
result = self.directory_connection.search_ext_s(
    base_dn,
    scope,  
    filterstr   = search_filter,
    attrlist    = attributes,
    sizelimit   = 900000,
    timeout     = -1,
    serverctrls = [ldap_controls,],
)

for dn, entry in result:
    ## do stuff
----- >8 >8 >8 -----

  Any pointers on what I'm doing wrong (or directions to documentation, but not just to the below page (I need a little more handholding, apparently)?  The "search_filter" and "attributes" variables are good, 'cause I _am_ getting the right results...just not _all_ the results.

  I got as far as https://www.python-ldap.org/en/python-ldap-3.3.0/reference/ldap-controls.html#ldap.controls.libldap.SimplePagedResultsControl but what I tried above isn't quite what I'm after.



More information about the python-ldap mailing list