我找到了从ldap获取数据的python方法,有一部分我遇到了问题
try:
ldap_result_id = ldapcon.search(base, scope, search_filter, attributes)
result_set = []
while 1:
result_type, result_data = ldapcon.result(ldap_result_id, 0)
if (result_data == []):
break
else:
if result_type == ldap.RES_SEARCH_ENTRY:
result_set.append(result_data)
except ldap.LDAPError, e:
print e
但主要是我在“ldapcon.result()”上有ldap错误
{'info': '00002024: LdapErr: DSID-0C060598, comment: No other operations may be performed on the connection while a bind is outstanding., data 0, v1db1', 'desc': 'Server is busy'}
它从3开始发生2次,所以下次尝试它可以成功! 你有一个好主意如何处理它? 把相同的try / except仅用于该函数并添加一些尝试计数器? 感谢
答案 0 :(得分:0)
我不能说它是否优雅和正确,但它有效
while 1:
try:
ldap_result_id = ldapcon.search(base, scope, search_filter, attributes)
result_set = []
result_type, result_data = ldapcon.result(ldap_result_id, 0, 2)
except ldap.LDAPError, e:
pass
if 'result_data' in locals():
if result_type == ldap.RES_SEARCH_ENTRY:
result_set.append(result_data)
return result_set[0][0][1]['departmentNumber'][0]
答案 1 :(得分:0)
我现在正在了解这一点。我希望这有帮助。我发现以下似乎完全符合我的需要:
ldap.ldapobject.ReconnectLDAPObject(dc, retry_max=5, retry_delay=2.0)
有关详细信息,请查看https://www.python-ldap.org/en/latest/reference/ldap.html#ldap-objects