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

4

2 回答 2

13

设置ldap.OPT_NETWORK_TIMEOUTldap 对象的选项。

import ldap

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

如果达到指定的超时,这将引发 ldap.SERVER_DOWN 异常。

于 2011-11-17T18:43:03.570 回答
4

出于某种原因ldap.OPT_NETWORK_TIMEOUT,我似乎永远不会超时,所以我ldap.OPT_TIMEOUT改用了(这会提高ldap.TIMEOUT):

import ldap

l = ldap.initialize('ldaps://ldap.example.com')
l.set_option(ldap.OPT_TIMEOUT, 10)
l.simple_bind_s('username', 'password')
于 2013-04-02T16:07:10.453 回答