0

我是 ldap3 库的新手,我正在尝试构建一个需要在 ldap 中搜索 55.000 个 uid 并检索其邮件属性的函数。

这是它的样子:

def ldapsearch(i):
server = Server('myserverurl:389')
try:
    with Connection(server) as conn:
        conn.search('ou=people,dc=xxx,dc=fr', '(&(objectclass=person)(uid='+i+'))', attributes=['mail', 'cn', 'uid'])
    entry = conn.entries[0]        
except:
    return'error search operation'
else:
    if (len(entry)!=0):
        return entry['mail']
    else:
        return'error uid not found'

但我无法让它工作......知道吗?

提前谢谢你的帮助,尼古拉斯

4

1 回答 1

0

我找到了答案:

    from ldap3 import Server, Connection, ALL    
    def ldapsearch(i):
        try:
            conn.search('ou=people,dc=xxxx,dc=fr', '(&(objectclass=person)(uid='+i+'))', attributes=['mail', 'cn', 'uid'])
            return conn.entries[0]['mail']        
        except:
            return'uid not found'

server = Server('myldapserver_url:389')
conn = Connection(server, auto_bind=True)

ldapsearch('myUid')

;-)

于 2017-10-26T12:37:37.587 回答