0

I'm new to ldap3 library and I'm trying to build a function that need to search ldap for 55.000 uids and retrieve their mail attribute.

Here is what it looks like :

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'

But I can't get it working... Any idea ?

Thx in advance for your help, Nicolas

1 Answers1

0

I found the answer :

    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')

;-)