首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LDAP: ldap.SIZELIMIT_EXCEEDED

LDAP: ldap.SIZELIMIT_EXCEEDED
EN

Stack Overflow用户
提问于 2010-07-31 20:41:54
回答 6查看 17.3K关注 0票数 12

当我运行这段代码时,我得到了一个ldap.SIZELIMIT_EXCEEDED错误:

代码语言:javascript
复制
import ldap

url = 'ldap://<domain>:389'
binddn = 'cn=<username> readonly,cn=users,dc=tnc,dc=org'
password = '<password>'

conn = ldap.initialize(url)
conn.simple_bind_s(binddn,password)

base_dn = "ou=People,dc=tnc,dc=org"
filter = '(objectClass=*)'
attrs = ['sn']

conn.search_s( base_dn, ldap.SCOPE_SUBTREE, filter, attrs )

其中username是我的实际用户名,password是我的实际密码,domain是实际的域。

我不明白为什么会这样。有没有人能说点什么?

EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2010-07-31 21:09:05

手册:http://www.python-ldap.org/doc/html/ldap.html

异常ldap.SIZELIMIT_EXCEEDED

已超过LDAP大小限制。这可能是由于LDAP服务器上的sizelimit配置造成的。

我认为这里最好的办法是限制从服务器接收的消息的sizelimit。可通过设置属性LDAPObject.sizelimit (已弃用)或在使用search_ext()时使用sizelimit参数来执行此操作

你还应该确保你的绑定实际上是成功的。

票数 6
EN

Stack Overflow用户

发布于 2020-05-16 07:02:47

您之所以会遇到这种异常,很可能是因为您正在与之通信的服务器的结果比单个请求返回的结果多。为了解决这个问题,你需要使用分页结果,这可以通过使用SimplePagedResultsControl来完成。

这是一个Python3实现,它是我在大量编辑我找到的hereofficial documentation之后想出来的。在撰写本文时,它可以与pip3包python-ldap版本3.2.0一起使用。

代码语言:javascript
复制
def get_list_of_ldap_users():
    hostname = "<domain>:389"
    username = "username_here"
    password = "password_here"
    base = "ou=People,dc=tnc,dc=org"

    print(f"Connecting to the LDAP server at '{hostname}'...")
    connect = ldap.initialize(f"ldap://{hostname}")
    connect.set_option(ldap.OPT_REFERRALS, 0)
    connect.simple_bind_s(username, password)
    search_flt = "(objectClass=*)"
    page_size = 500 # how many users to search for in each page, this depends on the server maximum setting (default highest value is 1000)
    searchreq_attrlist=["sn"] # change these to the attributes you care about
    req_ctrl = SimplePagedResultsControl(criticality=True, size=page_size, cookie='')
    msgid = connect.search_ext(base=base, scope=ldap.SCOPE_SUBTREE, filterstr=search_flt, attrlist=searchreq_attrlist, serverctrls=[req_ctrl])

    total_results = []
    pages = 0
    while True: # loop over all of the pages using the same cookie, otherwise the search will fail
        pages += 1
        rtype, rdata, rmsgid, serverctrls = connect.result3(msgid)
        for user in rdata:
            total_results.append(user)

        pctrls = [c for c in serverctrls if c.controlType == SimplePagedResultsControl.controlType]
        if pctrls:
            if pctrls[0].cookie: # Copy cookie from response control to request control
                req_ctrl.cookie = pctrls[0].cookie
                msgid = connect.search_ext(base=base, scope=ldap.SCOPE_SUBTREE, filterstr=search_flt, attrlist=searchreq_attrlist, serverctrls=[req_ctrl])
            else:
                break
        else:
            break
    return total_results

这将返回所有用户的列表,但您可以根据需要对其进行编辑,以便在不出现SIZELIMIT_EXCEEDED问题的情况下返回您想要的内容:)

票数 4
EN

Stack Overflow用户

发布于 2011-06-29 07:07:51

收到此错误时,请参阅此处了解如何处理:

How get get more search results than the server's sizelimit with Python LDAP?

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3378142

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档