Python-LDAP simple_bind_s timeout

本小妞迷上赌 提交于 2021-02-07 03:13:31

问题


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


回答1:


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.




回答2:


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')


来源:https://stackoverflow.com/questions/6679910/python-ldap-simple-bind-s-timeout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!