Python-LDAP simple_bind_s timeout
Asked Answered
V

2

8

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

Vorous answered 13/7, 2011 at 13:44 Comment(0)
H
16

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.

Harrie answered 17/11, 2011 at 18:43 Comment(0)
C
6

For some reason ldap.OPT_NETWORK_TIMEOUT never seems to time out for me, so I used ldap.OPT_TIMEOUT instead (which will raise ldap.TIMEOUT):

import ldap

l = ldap.initialize('ldaps://ldap.example.com')
l.set_option(ldap.OPT_TIMEOUT, 10)
l.simple_bind_s('username', 'password')
Cowie answered 2/4, 2013 at 16:7 Comment(1)
I may be mistaken, but from what I can tell, the difference between OPT_NETWORK_TIMEOUT and OPT_TIMEOUT is that the "network" option is for the initial connection: fail to connect within 10 seconds, raise exception. The OPT_TIMEOUT option seems to be for actions taken on the LDAP server: attempt to create a new record and it takes longer than 10 seconds, raise exception.Supererogatory

© 2022 - 2024 — McMap. All rights reserved.