【问题标题】:LDAP3 Module getting more than 1000 results or alternativesLDAP3 模块获得超过 1000 个结果或备选方案
【发布时间】:2020-03-13 17:43:35
【问题描述】:
# import class and constants
from ldap3 import Server, Connection, ALL, SUBTREE

# define the server
s = Server(host='xyz', port=xxxx, use_ssl=True, get_info='ALL')
c = Connection(s, auto_bind='NONE', version=3, authentication='ANONYMOUS', client_strategy='SYNC', auto_referrals=True, check_names=True, read_only=False, lazy=False, raise_exceptions=False)

c.bind()
results = c.extend.standard.paged_search(
    search_base = 'Ou=XYZ,dc=org,dc=com',
    search_filter = '(AppID=*)',
    search_scope = SUBTREE,
    get_operational_attributes=True,
    attributes=['*'],
    generator=True,
    paged_size=None
)
i=0

for entries in results:
    print(entries)
    i+=1
print(i)

我正在尝试连接到特定端口上的服务器并进行匿名 SSL 身份验证。我编写了上面的脚本来获取“Ap​​pID = *”的结果。我只能打印 1000 条记录,然后遇到以下错误:

Traceback(最近一次调用最后一次):文件“C:/Fetch data.py”,第 43 行, 在 对于结果中的条目:文件“C:\Users\xyz\AppData\Local\Programs\Python\Python36\lib\site-packages\ldap3\extend\standard\PagedSearch.py​​”, 第 75 行,在 paged_search_generator raise LDAPOperationResult(result=result['result'], description=result['description'], dn=result['dn'], message=result['message'], response_type=result['type']) ldap3.core.exceptions.LDAPSizeLimitExceededResult: LDAPSizeLimitExceededResult - 4 - sizeLimitExceeded - 无 - 无 - searchResDone - 无

我已经尝试过Conquering Active Directory's 1000 record limit提供的解决方案

我尝试过查看文档LDAP3 Docs ,但没有成功。有没有办法读取完整的输出。 (我想有超过 5k 条记录)

【问题讨论】:

    标签: python python-3.x active-directory ldap3


    【解决方案1】:

    这里的问题是您的代码会生成一个生成器对象。

    from ldap3 import Server, Connection, SUBTREE
    import ldap3
    total_entries = 0
    # define the server
    s = Server(host='xyz', port=xxxx, use_ssl=True, get_info=ldap3.NONE)
    c = Connection(s,authentication='ANONYMOUS') 
    # subtitute your filter here 
    filter = '(&(objectClass=group)(sAMAccountName=))'
    entry_generator = c.extend.standard.paged_search(search_base = 'Ou=XYZ,dc=org,dc=com',
                                                     search_filter = filter,
                                                     search_scope = SUBTREE,
                                                     get_operational_attributes=True,
                                                     attributes = ['*'],
                                                     paged_size = 1000,
                                                     generator=True)
    for entry in entry_generator:
        total_entries += 1
        print(entry['dn'], entry['attributes'])
    print('Total entries retrieved:', total_entries) 
    

    这应该会为您提供所需的所有详细信息。 参考ldap3 documents

    【讨论】:

    • 我尝试了类似的方法。你已经回答了我的问题。谢谢! :D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多