Help - Classes and attributes

rh0dium sklass at
Thu Jul 14 03:26:03 CEST 2005

Hi all,

I believe I am having a fundamental problem with my class and I can't
seem to figure out what I am doing wrong.  Basically I want a class
which can do several specific ldap queries.  So in my code I would have
multiple searches.  But I can't figure out how to do it without it

The error is straightforward ..

LDAP Version 2.0.8
Traceback (most recent call last):
  File "./", line 62, in ?
  File "./", line 40, in search
    ldap_result_id = l.search_s(baseDN, searchScope, searchAttrs,
AttributeError: NSCLdap instance has no attribute 'search_s'

The code is also I believe straight forward..

import ldap

class NSCLdap:

    def __init__(self,server=""):
        who=""; cred=""
            print "LDAP Version", ldap.__version__
            l.simple_bind_s(who, cred)
        except ldap.LDAPError, error_message:
            print "Couldn't Connect to %s  %s " %

    def search(self, baseDN="",
retrieveAttrs=None,searchAttrs="cn=*klass*" ):
        searchScope = ldap.SCOPE_SUBTREE
            ldap_result_id = l.search_s(baseDN, searchScope,
searchAttrs, retrieveAttrs)
            result_set = []
            while 1:
                result_type, result_data = l.result(ldap_result_id, 0)
                if (result_data == []):
                        ## here you don't have to append to a list
                        ## you could do whatever you want with the
individual entry
                        ## The appending to list is just for
                        if result_type == ldap.RES_SEARCH_ENTRY:
            print result_set
        except ldap.LDAPError, error_message:
            print "Errors on Search %s " % error_message

    def setBaseDN(self, baseDN=""):
        return baseDN

if __name__ == '__main__':

    l = NSCLdap()

I would love some pointers - clearly my code thinks that search_s is an
attribute of my class but it's not..


More information about the Python-list mailing list