2

I want to paginate the results of an ldap query so that I get 50 users per query for each page. The documentation here http://ldap3.readthedocs.io/searches.html?highlight=generator suggests that using a generator is the simplest way to do this, however it doesn't provide any detail as to how to use it to achieve pagination. When I iterate through the generator object, it prints out every user entry, even though I specified 'paged_size=5' in my search query. Can anyone explain to me what's going on here? Thanks!!

Stefan
  • 51
  • 1
  • 4

2 Answers2

0

Try setting the paged_criticality parameter to True. It could be that the server is not capable of performing a paged search. If that's the case and paged_criticality is True the search will fail rather than returning all users.

0

This is a similar system that I used:

# Set up your ldap connection
conn = Connection(*args)

# create a generator
entry_generator = conn.extend.standard.paged_search(
        search_base=self.dc, search_filter=query[0],
        search_scope=SUBTREE, attributes=self.user_attributes,
        paged_size=1, generator=True)

# Then get your results:
results = []
for entry in entry_generator:
    total_entries += 1
    results.append(entry)
    if total_entries % 50 == 0:
        # do something with results

Otherwise try setting the page_size to 50 and get results like that.

Daniel Lee
  • 7,189
  • 2
  • 26
  • 44