Totally stumped on how to use async.

Ryan Parrish RyanP at
Thu Jan 13 18:39:17 CET 2005

Let me preface by saying that I am kind of a newbie with LDAP.  
Here is my problem, I would like to use python-ldap to query the proxyAddresses on my AD domain controller, and eventually write it out to a file.  But since this is AD I have to limit my queries to under 1000 results.  
I am trying to mimic the functionality of this Perl script

1.) When I use the example on the site for asynchronies queries, I don't get all the results - I get 2000 (which I don't understand why, but there is actually 3106)
2.) The way I understand 'retrieveAttribuites' to work would be that I only retrieve one particular attribute for each 'cn', and that is how it appears to work in the 'directoyassist' 3rd party script off the site.  So I figured that I could put ['proxyAddresses'] in there and only receive the proxyAddresses, but when I use anything except None I get no results back.

Here is what I have, it is almost a verbatim copy of the example, if you could just give me some pointers on how to use the async queries I will be on my way. Thanks. 
PS I have tried on both my Linux and win box and get the exact same results.

#!/usr/bin/env python
import ldap
from string import split

    l ="")
    l.simple_bind_s('A user name','*****') 
except ldap.LDAPError, e:
    print e

baseDN = "dc=foxracing,dc=com"
searchScope = ldap.SCOPE_SUBTREE
retrieveAttributes = None
#sizelimit = 990

searchFilter = "(& (mailnickname=*) (| (&(objectCategory=person) \
(objectClass=user)(!(homeMDB=*))(!(msExchHomeServerName=*))) \
(&(objectCategory=person)(objectClass=user)(|(homeMDB=*) \
(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=contact)) \
(objectCategory=group)(objectCategory=publicFolder) ))"

    ldap_result_id =, searchScope, searchFilter, retrieveAttributes)
    while 1:
	result_type, result_data = l.result(ldap_result_id, 0)
	if (result_data == []):
	    if result_type == ldap.RES_SEARCH_ENTRY:
		for entry in result_data[0][1]['proxyAddresses']:
		    if 'SMTP' in entry:
			email = "%s OK" % (split(entry, ':')[1])
			print email
except ldap.LDAPError, e:
    print e


Ryan Parrish
ryanp at
IT Dept.
408-776-8633 extension 1229
Please direct all support questions to -
(¯`·.¸¸.-> itsupport at


More information about the python-ldap mailing list