Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python:如何设置Python ldap以忽略引用?_Python_Python 2.7_Ldap_Referrals_Python Ldap - Fatal编程技术网

Python:如何设置Python ldap以忽略引用?

Python:如何设置Python ldap以忽略引用?,python,python-2.7,ldap,referrals,python-ldap,Python,Python 2.7,Ldap,Referrals,Python Ldap,如何避免在以下代码中出现(未记录的)异常 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_interac

如何避免在以下代码中出现(未记录的)异常

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恰好是一个引用。当我运行此代码时,我将
引用
作为输出

我希望PythonLDAP跳过它或忽略它而不抛出奇怪的异常(我找不到关于它的文档)


(这可能有帮助或没有帮助)问题发生在我在树中搜索baseDN upper时。当我搜索“ou=xx,dc=xxx,dc=com”时,它开始冻结在我的生产环境中,而在开发环境中,一切都很好。当我开始看它时,我发现它在转介分支上冻结了。我如何告诉python ldap忽略引用?上面的代码没有按我所希望的那样工作。

这是一个工作示例,请查看是否有帮助

def ldap_initialize(remote, port, user, password, use_ssl=False, timeout=None):
    prefix = 'ldap'
    if use_ssl is True:
        prefix = 'ldaps'
        # ask ldap to ignore certificate errors
        ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)

    if timeout:
        ldap.set_option(ldap.OPT_NETWORK_TIMEOUT, timeout)

    ldap.set_option(ldap.OPT_REFERRALS, ldap.OPT_OFF)
    server = prefix + '://' + remote + ':' + '%s' % port
    l = ldap.initialize(server)
    l.simple_bind_s(user, password)