如何使用 Python LDAP 获得比服务器大小限制更多的搜索结果?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2073574/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get more search results than the server's sizelimit with Python LDAP?
提问by Dave Kirby
I am using the python-ldapmodule to (amongst other things) search for groups, and am running into the server's size limit and getting a SIZELIMIT_EXCEEDED
exception. I have tried both synchronous and asynchronous searches and hit the problem both ways.
我正在使用python-ldap模块(除其他外)搜索组,并且遇到服务器的大小限制并出现SIZELIMIT_EXCEEDED
异常。我尝试了同步和异步搜索,并以两种方式解决了问题。
You are supposed to be able to work round this by setting a paging control on the search, but according to the python-ldap docs these controls are not yet implemented for search_ext()
. Is there a way to do this in Python? If the python-ldap
library does not support it, is there another Python library that does?
您应该能够通过在搜索上设置分页控件来解决此问题,但根据 python-ldap 文档,这些控件尚未针对search_ext()
. 有没有办法在 Python 中做到这一点?如果python-ldap
库不支持它,是否有另一个 Python 库支持?
回答by Christian Oudard
Here are some links related to paging in python-ldap.
这里有一些与 python-ldap 中的分页相关的链接。
- Documentation: http://www.python-ldap.org/doc/html/ldap-controls.html#ldap.controls.SimplePagedResultsControl
- Example code using paging: http://www.novell.com/coolsolutions/tip/18274.html
- More example code: http://google-apps-for-your-domain-ldap-sync.googlecode.com/svn/trunk/ldap_ctxt.py
回答by Dave Kirby
After some discussion on the python-ldap-dev mailing list, I can answer my own question.
在对 python-ldap-dev 邮件列表进行了一些讨论后,我可以回答我自己的问题。
Page controls ARE supported by the Python lDAP module, but the docs had not been updated for search_ext to show that. The example linked by Gorgaporshows how to use the ldap.controls.SimplePagedResultsControl to read the results in pages.
Python lDAP 模块支持页面控件,但尚未针对 search_ext 更新文档以显示这一点。在通过Gorgapor链接例子展示了如何使用ldap.controls.SimplePagedResultsControl在页面读取结果。
However there is a gotcha. This will work with Microsoft Active Directory servers, but not with OpenLDAP servers (and possibly others, such as Sun's). The LDAP controls RFCis ambiguous as to whether paged controls should be allowed to override the server's sizelimit setting. On ActiveDirectory servers they can by default while on OpenLDAP they cannot, but I think there is a server setting that will allow them to.
然而,有一个问题。这将适用于 Microsoft Active Directory 服务器,但不适用于 OpenLDAP 服务器(可能还有其他服务器,例如 Sun 的)。该LDAP控制RFC是模糊的,以分页控件是否应该被允许覆盖服务器的设置的sizeLimit。在 ActiveDirectory 服务器上,默认情况下它们可以,而在 OpenLDAP 上则不能,但我认为有一个服务器设置允许它们。
So even if you implement the paged control, there is still no guarantee that it will get all the objects that you want. Sigh
所以即使你实现了分页控件,仍然不能保证它会得到你想要的所有对象。叹
Also paged controls are only available with LDAP v3, but I doubt that there are many v2 servers in use.
此外,分页控件仅适用于 LDAP v3,但我怀疑是否有许多 v2 服务器在使用。