当我运行这段代码时,我得到了一个ldap.SIZELIMIT_EXCEEDED错误:
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是实际的域。
我不明白为什么会这样。有没有人能说点什么?
发布于 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参数来执行此操作
你还应该确保你的绑定实际上是成功的。
发布于 2020-05-16 07:02:47
您之所以会遇到这种异常,很可能是因为您正在与之通信的服务器的结果比单个请求返回的结果多。为了解决这个问题,你需要使用分页结果,这可以通过使用SimplePagedResultsControl来完成。
这是一个Python3实现,它是我在大量编辑我找到的here和official documentation之后想出来的。在撰写本文时,它可以与pip3包python-ldap版本3.2.0一起使用。
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问题的情况下返回您想要的内容:)
发布于 2011-06-29 07:07:51
https://stackoverflow.com/questions/3378142
复制相似问题