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

sur*_*rya 2 python python-2.7 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
Run Code Online (Sandbox Code Playgroud)

在尝试组合搜索过滤器时:出现此错误.

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

小智 7

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

search_filter = "(&(city=Bangalore)(manageruid=278586))"
Run Code Online (Sandbox Code Playgroud)