Python ldap3读取器只返回一个值

2024-10-03 11:17:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用pythonldap3从ldap检索用户。 这是我的设置

from ldap3 import Server, Connection, ObjectDef, AttrDef, Reader, Writer, ALL
server = Server('ldap://ldapserver:389', get_info=ALL)
conn = Connection(server, 'eTGlobalUserName=user,eTGlobalUserContainerName=Global Users,eTNamespaceName=CommonObjects,dc=iam,dc=eta', 'pass123', auto_bind=True)

使用连接对象进行搜索时,可以检索所有用户:

conn.search('eTGlobalUserContainerName=Global Users,eTNamespaceName=CommonObjects,dc=iam,dc=eta', '(objectclass=eTGlobalUser)')

但是,当我尝试使用Reader获取所有用户时,我只获取一个项目,它甚至不包含一个用户,这就是我所做的:

obj_person = ObjectDef('eTGlobalUser',conn)
r = Reader(conn,obj_person,'eTGlobalUserContainerName=Global Users,eTNamespaceName=CommonObjects,dc=iam,dc=eta')
r.search()

我有什么遗漏吗?你知道吗

编辑1 这是print(r)的输出:

This is the output of print(r):
CURSOR : Reader
CONN   : ldap://ldapserver:389 - cleartext - user: eTGlobalUserName=user,eTGlobalUserContainerName=Global Users,eTNamespaceName=CommonObjects,dc=asusisv-iam,dc=eta - not 
lazy - bound - open - <local: 10.150.8.169:54196 - remote: 10.145.10.123:389> - tls not started - listening - SyncStrategy - internal decoder
DEFS   : eTGlobalUser
ATTRS  : ['eTAccessControlList', ... , 'eTGlobalUserName', ... , 'objectClass']
BASE   : 'eTGlobalUserContainerName=Global Users,eTNamespaceName=CommonObjects,dc=iam,dc=eta' [SUB]
FILTER : '(objectClass=eTGlobalUser)'

Tags: 用户dcldapconnglobalusersreaderiam
1条回答
网友
1楼 · 发布于 2024-10-03 11:17:31

您可以使用^{}访问结果

Once a Reader cursor is populated with entries, you can get a specific entry with the standard index feature of List object.

Cursor对象还有一个快捷方式:使用r[0]r[1]等执行相同的操作。例如:

for entry in r.entries:
    print(entry.entry_dn) 
    print(entry.<attribute_name>)

# or
for entry in r:
    ...

如果得到0个条目,您可以print(r)查看如何构建读卡器光标,并检查CONNBASEFILTER(用于构建r.search() queries)是否从ObjectDef()Reader()中给出的参数正确转换。你知道吗

相关问题 更多 >