如何避免在下面的代码中出现(未记录的)异常?在
import ldap
import ldap.sasl
connection = ldap.initialize('ldaps://server:636', trace_level=0)
connection.set_option(ldap.OPT_REFERRALS, 0)
connection.protocol_version = 3
sasl_auth = ldap.sasl.external()
connection.sasl_interactive_bind_s('', sasl_auth)
baseDN = 'ou=org.com,ou=xx,dc=xxx,dc=com'
filter = 'objectclass=*'
try:
result = connection.search_s(baseDN, ldap.SCOPE_SUBTREE, filter)
except ldap.REFERRAL, e:
print "referral"
except ldap.LDAPError, e:
print "Ldaperror"
示例中给出的baseDN恰好是一个引用。当我运行这段代码时,我得到referral
作为输出。在
我想要的是pytholdap可以跳过它或忽略它而不抛出奇怪的异常(我找不到关于它的文档)?在
(这可能有帮助也可能没有)问题发生在我在树的上部搜索baseDN时。当我搜索'ou=xx,dc=xxx,dc=com'时,它开始冻结在我的生产环境中,而在开发env上一切都很好。当我开始看它时,我发现它冻结在转介分支机构。如何告诉pytholdap忽略引用?上面的代码没有我想要的那样工作。在
这是一个有效的例子,看看是否有用。在
相关问题 更多 >
编程相关推荐