[python3-ldap] Key error help

Andrew Hydle ahydle at gmail.com
Fri Mar 21 23:12:24 CET 2014


It is querying against Windows Server 2012 Active Directory. If I perform
the search on those URI's I dont believe it will return any of my users.
Those are specific schema containers for active directory. Is there a way I
can get it to not come back in the response?


On Fri, Mar 21, 2014 at 3:05 PM, Python3-ldap <python3ldap at gmail.com> wrote:

>  This means that the auto_referral is not working for that Uri.
> Can you tell me the server version you're connecting to? I could try to
> set up a lab server. In the meanwhile you should repeat the search in the
> contest specified in the result Uri.
>
> Giovanni
>
> gc
>  ------------------------------
> Da: Andrew Hydle <ahydle at gmail.com>
> Inviato: 21/03/2014 21.51
> A: python3ldap <python3ldap at gmail.com>
> Cc: python3-ldap at python.org
> Oggetto: Re: [python3-ldap] Key error help
>
> Hi Giovanni,
>
> I changed that as suggested but unfortunately I still get the same key
> error:
>
>  s = Server(args.srvr, port=int(args.sprt), get_info=GET_ALL_INFO,
> allowed_referral_hosts='*')
> c = Connection(s, auto_bind=True, client_strategy=STRATEGY_SYNC,
> user=args.user, password=args.pasw, authentication=AUTH_SIMPLE,
> auto_referrals=True)
>
> Can you think of anything else I could try?
>
> Thanks
>
> Andrew
>
>
> On Fri, Mar 21, 2014 at 12:04 PM, python3ldap <python3ldap at gmail.com>wrote:
>
>> 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
>> >
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python3-ldap/attachments/20140321/c6f1cc0a/attachment-0001.html>


More information about the python3-ldap mailing list