Hi all, I have a script which appears to work but it errors and the following output is given. My code is listed below..
Traceback (most recent call last): File "./ldap-nsc2.py", line 96, in ? truc.search() File "./ldap-nsc2.py", line 49, in search (result_type, result_data) = cnx.result(ldap_result_id, 0) File "/usr/local/lib/python2.4/site-packages/ldap/ldapobject.py", line 406, in result res_type,res_data,res_msgid = self.result2(msgid,all,timeout) File "/usr/local/lib/python2.4/site-packages/ldap/ldapobject.py", line 410, in result2 res_type, res_data, res_msgid, srv_ctrls = self.result3(msgid,all,timeout) File "/usr/local/lib/python2.4/site-packages/ldap/ldapobject.py", line 416, in result3 rtype, rdata, rmsgid, serverctrls = self._ldap_call(self._l.result3,msgid,all,timeout) File "/usr/local/lib/python2.4/site-packages/ldap/ldapobject.py", line 94, in _ldap_call result = func(*args,**kwargs) TypeError: an integer is required So I dig into the docs at /usr/local/lib/python2.4/site-packages/ldap/ldapobject.py to see what the problem is.. <snip> def result(self,msgid=ldap.RES_ANY,all=1,timeout=None): """ result([msgid=RES_ANY [,all=1 [,timeout=None]]]) -> (result_type, result_data) . . . """ <snip> So.. That's what I have in my code.. result_type, result_data = cnx.result(ldap_result_id, 0) Can Someone please point me in the right direction. I want to know WHY it's failing. I think it's right? Anyone? My Code... ---------------------------- import ldap class NSCLdap(object): def __init__(self, server="sc-ldap.nsc.com", baseDN="o=nsc.com", who=None, cred=None): self.server = server self.baseDN = baseDN if who is None: self.who = "" else: self.who = who if cred is None: self.cred = "" else: self.cred = cred self.connection = None def connect(self): print "LDAP Version", ldap.__version__ self.connection = ldap.open(self.server) self.connection.simple_bind_s( self.who, self.cred) self.connection.protocol_version=ldap.VERSION3 def search(self, baseDN=None, searchScope=ldap.SCOPE_SUBTREE, retrieveAttrs=None, searchAttrs="l=ny5*" ): cnx = self.connection if baseDN is None: baseDN = self.baseDN try: ldap_result_id = cnx.search_s(baseDN, searchScope, searchAttrs, retrieveAttrs) while 1: result_type, result_data = cnx.result(ldap_result_id, 0) if (result_data == []): break else: if result_type == ldap.RES_SEARCH_ENTRY: result_set.append(result_data) if len(result_set) == 0: print "No Results." return for i in range(len(result_set)): for entry in result_set[i]: try: name = entry[0][i]['cn'] email = entry[0][i]['mail'] phone = entry[0][i]['telephonenumber'] loc = entry[0][i]['l'] count = count + 1 print "%d.\nName: %s\nDescription: %s\nE-mail: %s\nPhone: %s\n" %\ (count, name, desc, email, phone) except: pass except ldap.LDAPError, error_message: print error_message if __name__ == '__main__': truc = NSCLdap() truc.connect() truc.search() -- http://mail.python.org/mailman/listinfo/python-list