[python3-ldap] Key error help

python3ldap python3ldap at gmail.com
Fri Mar 21 20:04:44 CET 2014


Hello Andrew,
there is no } missing, the problem is that your LDAP server returns as
second, third and fourth element of the response a Search Result
Referral that is a reference to another server:

{'uri': ['ldap://DomainDnsZones.domain.net/DC=DomainDnsZones,DC=domain,DC=net'],
'type': 'searchResRef'}
{'uri': ['ldap://ForestDnsZones.domain.net/DC=ForestDnsZones,DC=domain,DC=net'],
'type': 'searchResRef'}
{'uri': ['ldap://domain.net/CN=Configuration,DC=domain,DC=net'],
'type': 'searchResRef'}

 and doens't have any attributes. You can try to set the
auto_referrals parameter to True in the connection object and specify
a list of allowed_referrals_hosts in the Server object (you can set it
to '*' to allow all server referred in the response).

Let me know if this solve your problem.

Bye,
Giovanni
Have fun,
gc


2014-03-21 19:10 GMT+01:00 Andrew Hydle <ahydle at gmail.com>:
> Hi,
>
> I am getting a key error when I start looping through c.response. Looking at
> the data coming out of c.repsonse I am wondering if the dictionary that I am
> receiving is missing a }
>
> I am running python 3.4.0 / python3-ldap 0.9.0 on Windows 7
>
> [{'raw_attributes': {'displayName': [b'First Last'], 'description': [b'LDAP
> Description']}, 'dn': 'CN=First
> Last,OU=OU,OU=Users,OU=CITY,OU=company,DC=domain,DC=net', 'type':
> 'searchResEntry', 'attributes': {'displayName': ['First Last'],
> 'description': ['LDAP Description']}}, {'uri':
> ['ldap://DomainDnsZones.domain.net/DC=DomainDnsZones,DC=domain,DC=net'],'type':
> 'searchResRef'},
> {'uri':['ldap://ForestDnsZones.domain.net/DC=ForestDnsZones,DC=domain,DC=net'],
> 'type': 'searchResRef'}, {'uri':
> ['ldap://domain.net/CN=Configuration,DC=domain,DC=net'], 'type':
> 'searchResRef'}]
>
> {'displayName': ['First Last'], 'description': ['LDAP Description']}
> Traceback (most recent call last):
>   File "sapADImport.py", line 31, in <module>
>     print(r['attributes'])
> KeyError: 'attributes'
>
> -------------------------------------------
>
> from ldap3 import Server, Connection
> from ldap3 import AUTH_SIMPLE, STRATEGY_SYNC, STRATEGY_ASYNC_THREADED,
> SEARCH_SCOPE_WHOLE_SUBTREE, SEARCH_DEREFERENCE_ALWAYS, GET_ALL_INFO
>
> s = Server(args.srvr, port=int(args.sprt), get_info=GET_ALL_INFO)
> c = Connection(s, auto_bind=True, client_strategy=STRATEGY_SYNC,
> user=args.user, password=args.pasw, authentication=AUTH_SIMPLE)
>
> lfilter = '(&(objectCategory=person)(sAMAccountName=%s))' % uid.lower()
> result = c.search(search_base=args.bdn, search_filter=lfilter,
> search_scope=SEARCH_SCOPE_WHOLE_SUBTREE, attributes=['displayName',
> 'description'])
>
>
> print(c.response)
> if result:
> for r in c.response:
>     print(r['attributes'])
>
> else:
>     print('result', c.result)
>
> _______________________________________________
> python3-ldap mailing list
> python3-ldap at python.org
> https://mail.python.org/mailman/listinfo/python3-ldap
>


More information about the python3-ldap mailing list