<div dir="ltr">Hi Giovanni,<div><br></div><div>I changed that as suggested but unfortunately I still get the same key error:</div><div><br></div><div><div>s = Server(args.srvr, port=int(args.sprt), get_info=GET_ALL_INFO, allowed_referral_hosts='*')</div>
<div>c = Connection(s, auto_bind=True, client_strategy=STRATEGY_SYNC, user=args.user, password=args.pasw, authentication=AUTH_SIMPLE, auto_referrals=True)</div></div><div><br></div><div>Can you think of anything else I could try?</div>
<div><br></div><div>Thanks</div><div><br></div><div>Andrew</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Mar 21, 2014 at 12:04 PM, python3ldap <span dir="ltr"><<a href="mailto:python3ldap@gmail.com" target="_blank">python3ldap@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello Andrew,<br>
there is no } missing, the problem is that your LDAP server returns as<br>
second, third and fourth element of the response a Search Result<br>
Referral that is a reference to another server:<br>
<div class=""><br>
{'uri': ['ldap://<a href="http://DomainDnsZones.domain.net/DC=DomainDnsZones,DC=domain,DC=net'" target="_blank">DomainDnsZones.domain.net/DC=DomainDnsZones,DC=domain,DC=net'</a>],<br>
'type': 'searchResRef'}<br>
</div><div class="">{'uri': ['ldap://<a href="http://ForestDnsZones.domain.net/DC=ForestDnsZones,DC=domain,DC=net'" target="_blank">ForestDnsZones.domain.net/DC=ForestDnsZones,DC=domain,DC=net'</a>],<br>
'type': 'searchResRef'}<br>
</div><div class="">{'uri': ['ldap://<a href="http://domain.net/CN=Configuration,DC=domain,DC=net'" target="_blank">domain.net/CN=Configuration,DC=domain,DC=net'</a>],<br>
'type': 'searchResRef'}<br>
<br>
</div> and doens't have any attributes. You can try to set the<br>
auto_referrals parameter to True in the connection object and specify<br>
a list of allowed_referrals_hosts in the Server object (you can set it<br>
to '*' to allow all server referred in the response).<br>
<br>
Let me know if this solve your problem.<br>
<br>
Bye,<br>
Giovanni<br>
Have fun,<br>
gc<br>
<br>
<br>
2014-03-21 19:10 GMT+01:00 Andrew Hydle <<a href="mailto:ahydle@gmail.com">ahydle@gmail.com</a>>:<br>
<div><div class="h5">> Hi,<br>
><br>
> I am getting a key error when I start looping through c.response. Looking at<br>
> the data coming out of c.repsonse I am wondering if the dictionary that I am<br>
> receiving is missing a }<br>
><br>
> I am running python 3.4.0 / python3-ldap 0.9.0 on Windows 7<br>
><br>
> [{'raw_attributes': {'displayName': [b'First Last'], 'description': [b'LDAP<br>
> Description']}, 'dn': 'CN=First<br>
> Last,OU=OU,OU=Users,OU=CITY,OU=company,DC=domain,DC=net', 'type':<br>
> 'searchResEntry', 'attributes': {'displayName': ['First Last'],<br>
> 'description': ['LDAP Description']}}, {'uri':<br>
> ['ldap://<a href="http://DomainDnsZones.domain.net/DC=DomainDnsZones,DC=domain,DC=net'" target="_blank">DomainDnsZones.domain.net/DC=DomainDnsZones,DC=domain,DC=net'</a>],'type':<br>
> 'searchResRef'},<br>
> {'uri':['ldap://<a href="http://ForestDnsZones.domain.net/DC=ForestDnsZones,DC=domain,DC=net'" target="_blank">ForestDnsZones.domain.net/DC=ForestDnsZones,DC=domain,DC=net'</a>],<br>
> 'type': 'searchResRef'}, {'uri':<br>
> ['ldap://<a href="http://domain.net/CN=Configuration,DC=domain,DC=net'" target="_blank">domain.net/CN=Configuration,DC=domain,DC=net'</a>], 'type':<br>
> 'searchResRef'}]<br>
><br>
> {'displayName': ['First Last'], 'description': ['LDAP Description']}<br>
> Traceback (most recent call last):<br>
> File "sapADImport.py", line 31, in <module><br>
> print(r['attributes'])<br>
> KeyError: 'attributes'<br>
><br>
> -------------------------------------------<br>
><br>
> from ldap3 import Server, Connection<br>
> from ldap3 import AUTH_SIMPLE, STRATEGY_SYNC, STRATEGY_ASYNC_THREADED,<br>
> SEARCH_SCOPE_WHOLE_SUBTREE, SEARCH_DEREFERENCE_ALWAYS, GET_ALL_INFO<br>
><br>
> s = Server(args.srvr, port=int(args.sprt), get_info=GET_ALL_INFO)<br>
> c = Connection(s, auto_bind=True, client_strategy=STRATEGY_SYNC,<br>
> user=args.user, password=args.pasw, authentication=AUTH_SIMPLE)<br>
><br>
> lfilter = '(&(objectCategory=person)(sAMAccountName=%s))' % uid.lower()<br>
> result = c.search(search_base=args.bdn, search_filter=lfilter,<br>
> search_scope=SEARCH_SCOPE_WHOLE_SUBTREE, attributes=['displayName',<br>
> 'description'])<br>
><br>
><br>
> print(c.response)<br>
> if result:<br>
> for r in c.response:<br>
> print(r['attributes'])<br>
><br>
> else:<br>
> print('result', c.result)<br>
><br>
</div></div>> _______________________________________________<br>
> python3-ldap mailing list<br>
> <a href="mailto:python3-ldap@python.org">python3-ldap@python.org</a><br>
> <a href="https://mail.python.org/mailman/listinfo/python3-ldap" target="_blank">https://mail.python.org/mailman/listinfo/python3-ldap</a><br>
><br>
</blockquote></div><br></div>