I need to get all mail address from ldap for a given cn...
The issue is when I try to put:
- In a list like:
mylist = [cn, mail] - In a dict like:
mydict[cn] = mail
But I get something like ['cn', mail: [email protected]] and the result I want is this [cn, [email protected]].
Here's the code:
basedn = config['ldap']['basedn']
attribs = ['mail']
data = []
for account in logon_name:
sfilter = f'(cn={account})'
ldap_conn.search(
basedn,
sfilter,
attributes=attribs
)
if ldap_conn.entries:
test = ldap_conn.entries[0].mail
data.append([account, test])
print(test)
print(data)
And the result:
print(test)
The output:
When I try to put the variable test value give:
[['xxxxx', mail: [email protected]]]
I don't know where the mail is provided, and why I don't see it in the test variable and the print(test).
Someone has an idea?
I've set up a simple test environment using the bitnami openldap image and the following test data:
This lets us attempt to reproduce your issue:
So here we see that when you ask for
ldap_conn.entries[0].mail, you're getting back anAttributeobject. Let's look at the attributes available on anAttribute:The
valueattribute looks promising:Which suggests you actually want:
Here's a runnable example:
Which produces as output: