[Tutor] Tutor Digest, Vol 114, Issue 11

Marc marc at marcd.org
Mon Aug 5 13:56:22 CEST 2013


>
> I am trying to do a ldap search against a LDAP server, like this:
>
> ld = ldap.initialize(ldapURI)
> ld.simple_bind_s(ldapBindDn,ldapBindPass)
> zones =
> ld.search_st(ldapBase,ldap.SCOPE_SUBTREE,'(&(objectclass=dnszone)(cn=*))',['dnszonename','modifytimestamp'],timeout=5)
>
> It times out after 5 seconds, and if I don't use timeout, it will hang
> up for ever.
>
> Now, if I search fog cn=ab*, a much limited search it will return the
> search
> results. Thinking that it could be a limitation from the server side, I've
> done
> the same search with ldapsearch in bash, and it gets what is expected.
>
> I am using ipython, and python 2.6 in a linux OS.
>
> My question is: How can I try to debug this issue?
>
> Thank you in advance fo your support,
> Antonio.
>
>
> Error output:
>
> In [122]: zones =
> ld.search_st(ldapBase,ldap.SCOPE_SUBTREE,'(&(objectclass=dnszone)(cn=*))',['dnszonename','modifytimestamp'],timeout=5)
> ERROR: An unexpected error occurred while tokenizing input
> The following traceback may be corrupted or invalid
> The error message is: ('EOF in multi-line statement', (379, 0))
>
> ---------------------------------------------------------------------------
> TIMEOUT                                   Traceback (most recent call
> last)
>
> /home/admin/afm/tinydns_databases/<ipython console> in <module>()
>
> /usr/lib64/python2.6/site-packages/ldap/ldapobject.pyc in search_st(self,
> base, scope, filterstr, attrlest, attrsonly, timeout)
>     517
>     518   def
> search_st(self,base,scope,filterstr='(objectClass=*)',attrlist=None,attrsonly=0,timeout=-1):
> --> 519     return
> self.search_ext_s(base,scope,filterstr,attrlist,attrsonly,None,None,timeout)
>     520
>     521   def set_cache_options(self,*args,**kwargs):
>
>
> [...]
>
>
> /usr/lib64/python2.6/site-packages/ldap/ldapobject.pyc in _ldap_call(self,
> func, *args, **kwargs)
>      94     try:
>      95       try:
> ---> 96         result = func(*args,**kwargs)
>      97         if __debug__ and self._trace_level>=2:
>      98           if func.__name__!="unbind_ext":


Hi  -  An example of the code (relevant snippet) I use is below - a little
different technique, but maybe it will help you figure it out (disclaimer:
I am by NO means an expert with Python - but I can get by):

import ldap
import sys
import string

if __name__ == "__main__":


    try:
        outfile = open("LDAPOut.txt",'w')
        outfile.write("CN|Created|LastLogin|Login\n")
        con = ldap.initialize("<LDAP Server>")
        con.simple_bind(who="cn=<UserID>,o=<O>", cred="<Password>")

        print "success"

    except:
        print "failure"


    res = con.search_s("ou=<OU>,o=<O>",  ldap.SCOPE_SUBTREE,
'objectClass=user' ,['createTimestamp','lastLoginTime','LoginTime'])

Manipulate the 'res =' statement to get the attributes you want.



More information about the Tutor mailing list