2015-09-08 51 views
0

我發現蟒蛇的方式從LDAP獲取數據時如何處理LDAP請求,還有就是我有問題,獲得「服務器忙」

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 

但主要是我有在「LDAP錯誤的一部分ldapcon.result()「

{'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'} 

它發生2次3次,所以下次嘗試它可以成功! 你有一些不錯的想法如何處理它? 把相同的嘗試/除了只爲該功能,並添加一些嘗試計數器? 感謝

回答

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]