python-ldap search_s hanging problem on Linux box

Todd Hanson Todd.Hanson at
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):



import ldap

import ldap.sasl

import sys


server = 'ldap://'

user_id = ????

pw = ????


def main():


        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."


    except ldap.LDAPError, e:

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

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


            print 'Error - ' + str(e)




        print 'Connected'



            #con.timeout = 10

            #con.network_timeout = 10


            base_dn = 'dc=mariner,dc=local'

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

            attrs =

            timeout = 3

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


            for dn,entry in results:

                if dn != None:

                    print 'Processing',repr(dn)

                    print entry['sAMAccountName']

                    print entry['displayName']

                    print entry['memberOf']



            print ""

            print "Connection Closed"

        except ldap.LDAPError, e:

            print 'Error - ' + str(e)



# End Of Code




if __name__=="__main__":



Thank You


Todd J. Hanson

todd.hanson at

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the python-ldap mailing list