From: Guruprasad <lgp...@gm...> - 2009-09-20 14:10:13
|
Hi, I have been trying to write a function to search a LDAP directory by using the python-ldap APIs. Here is the code I have written: <snip> def getNextUid(): uidList=[] try: l=ldap.initialize(ldap_host) l.bind_s(ldap_admin_dn,ldap_admin_pass) ldap_result=l.search(ldap_base_dn,ldap.SCOPE_SUBTREE,'cn=*',['uidNumber']) while 1: result_type, result_data=l.result(ldap_result,0) if (result_data == []): break a=result_data[0][1]['uidNumber'] print a except ldap.SERVER_DOWN: print "LDAP server down" </snip> What I am trying to do in this piece of code is get the list of the values of 'uidNumber' attribute. The search operation returns a list containing a tuple. The tuple contains the DN as one value and a dictionary with uidNumber and its value. I am trying to extract the value of the uidNumber. I found that result_data was a dictionary having a key 'uidNumber', but when I try to print its value, I get a KeyError. Strangely, when I print result_data.keys(), 'uidNumber' is present. Thank you. Regards, Guruprasad. |