如何在python LDAP中组合搜索过滤器



在访问LDAP数据时,我不断收到Size Limit Exceeded错误。

谷歌上提出的解决方案之一要求更严格的搜索过滤器。

如何在python LDAP中组合两个或多个搜索过滤器?使用建议的(|(filter1)(filter2))会产生错误。

这是查询:

baseDn = "ou=active, ou=employees, ou=people, o=xxxxx.com";
searchScope = ldap.SCOPE_SUBTREE
#retrieve Certain attributes
retrieveAttributes = ["manageruid","manager","cn"]
search_query = raw_input("Enter the query :")
#This searchFilter needs to be more specific
searchFilter = "city=" + "Bangalore"
try :
   ldap_result_id = l.search(baseDn, searchScope, searchFilter,   retrieveAttributes)
   result_set = []
   while 1:
       result_type, result_data = l.result(ldap_result_id, 0)
       if(result_data == []):
           break
       else:
           if result_type == ldap.RES_SEARCH_ENTRY:
               result_set.append(result_data)
       #print result_set
       print len(result_set)   
except ldap.LDAPError, e:
    print e

尝试组合搜索过滤器时:这个错误来了。

 File "practice.py", line 33
    search_filter = (&("city=Bangalore")("manageruid=278586"))
                     ^
SyntaxError: invalid syntax 

我认为search_filter必须是一个字符串。你试过这个吗?

search_filter = "(&(city=Bangalore)(manageruid=278586))"

最新更新