python-ldap search_s hanging problem on Linux box

Todd Hanson Todd.Hanson at mariner-qs.com
Tue Jun 23 21:02:49 CEST 2009


I have a query that was written in python (2.5) utilizing the
python-ldap package (newest stable version for both Windows and Linux)
to query an Active Directory server for a user's group membership.  The
code works fine on my test machine (2-3 seconds for result) which is
Windows based but when I move the code over and run it on our production
Linux (Ubuntu 8.10) server the query hangs for exactly 5 minutes and
then displays the results.  Does anyone have any ideas where this delay
might be coming from and how I can resolve the issue? 

 

The code is (please note I replaced some real data i.e. login, password,
etc with "????" but in my code real names are there):

 

#!/usr/bin/envpython

import ldap

import ldap.sasl

import sys

 

server = 'ldap://10.200.1.10'

user_id = ????

pw = ????

 

def main():

    try:

        con = ldap.initialize(server)

        con.simple_bind_s(user_id, pw)

        print 'Connection Made'

    except ldap.INVALID_CREDENTIALS:

        print "Your username or password is incorrect."

        sys.exit()

    except ldap.LDAPError, e:

        if type(e.message) == dict and e.message.has_key('desc'):

            print 'Error - ' + e.message['desc']

        else:

            print 'Error - ' + str(e)

            sys.exit()

    finally:

 

        print 'Connected'

 

        try:

            #con.timeout = 10

            #con.network_timeout = 10

 

            base_dn = 'dc=mariner,dc=local'

            filter = "(memberOf=CN=????,CN=Users,DC=????,DC=local)"

            attrs =
['sn','mail','cn','sAMAccountName','displayName','memberOf']

            timeout = 3

            results = con.search_s(base_dn, ldap.SCOPE_SUBTREE, filter,
attrs)

 

            for dn,entry in results:

                if dn != None:

                    print 'Processing',repr(dn)

                    print entry['sAMAccountName']

                    print entry['displayName']

                    print entry['memberOf']

 

            con.unbind()

            print ""

            print "Connection Closed"

        except ldap.LDAPError, e:

            print 'Error - ' + str(e)

            sys.exit()

 

# End Of Code

##

###

####

if __name__=="__main__":

    main()

 

Thank You

 

Todd J. Hanson

todd.hanson at mariner-qs.com

 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20090623/07b5067a/attachment.html>


More information about the python-ldap mailing list