python-ldap: searching without specifying an OU?

hotani hotani at gmail.com
Tue Apr 22 13:40:42 EDT 2008


I am attempting to pull info from an LDAP server (Active Directory),
but cannot specify an OU. In other words, I need to search users in
all OU's, not a specific one.

Here is what works:

con = ldap.initialize("ldap://server.local")
con.simple_bind_s('user at domain', pass)
result = con.search_ext_s(
  'OU=some office, DC=server, DC=local',
  ldap.SCOPE_SUBTREE,
  "sAMAccountName=username", ['mail']
)[0][1]

for i in result:
  print "%s = %s" (i, result[i])

But i really need it to not require an OU. When I remove that part, it
breaks. Or it just won't find the user. Is there a proper syntax for
this that I'm missing? Maybe a different search function?



More information about the Python-list mailing list