简体   繁体   English

Python-LDAP simple_bind_s 超时

[英]Python-LDAP simple_bind_s timeout

Is there a way to set timeout for "simple_bind_s" in python-LDAP manually?有没有办法手动为 python-LDAP 中的“simple_bind_s”设置超时? I have tested ldapObject.timeout = 10 it did not work for me.我已经测试了 ldapObject.timeout = 10 它对我不起作用。 Any ideas?有任何想法吗?

Thanks in advance..提前致谢..

Set the option ldap.OPT_NETWORK_TIMEOUT for the ldap object.为 ldap object 设置选项ldap.OPT_NETWORK_TIMEOUT

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.如果达到指定的超时,这将引发 ldap.SERVER_DOWN 异常。

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 ):出于某种原因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')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM