Python-LDAP simple_bind_s timeout

kursat picture kursat · Jul 13, 2011 · Viewed 9.7k times · Source

Is there a way to set timeout for "simple_bind_s" in python-LDAP manually? I have tested ldapObject.timeout = 10 it did not work for me. Any ideas?

Thanks in advance..

Answer

robots.jpg picture robots.jpg · Nov 17, 2011

Set the option ldap.OPT_NETWORK_TIMEOUT for the ldap object.

import ldap

l = ldap.initialize('ldap://servername:389')
l.set_option(ldap.OPT_NETWORK_TIMEOUT, 10.0)
l.simple_bind_s('username', 'password')

This will raise a ldap.SERVER_DOWN exception if the specified timeout is reached.