Crazysexman
Crazysexman

Reputation: 61

Python ldap3 search creates an empty entry

The first step of my program requires I search through the company's active directory and find a list of users by department. Here is my code so far:

from ldap3 import Server, Connection, SUBTREE, ALL
server = Server('my.company.local', get_info=ALL)
conn = Connection(server, auto_bind=True)
conn.search('dc=my, dc=company, dc=local', '(givenName=Charles)')
print(conn.entries)

However, no matter what I put in the search filter part of conn.search, no data is found in my entries log. The entries log is an empty list. When I pull up Active Directory Users and Computer, I can go through each department and find names and search their attribute editor (and yes there is a GivenName=Charles in there). Please point me in the right direction as to why there's no data returned as I'm running out of ideas. Thanks.

EDIT: If it's relevant, print(server.schema) returns None. Also, print(conn) returns as insert my.company.local here:389 - cleartext - user: None - not lazy - bound - open - <local: 10.5.112.213:63755 - remote: 10.5.107.41:389> - tls not started - listening - SyncStrategy - internal decoder Which makes me pretty certain I'm connected.

Upvotes: 2

Views: 4367

Answers (3)

Crazysexman
Crazysexman

Reputation: 61

So both cannatag and ig0774 were correct. Providing user credentials is necessary to use the search function. Otherwise the search function returns an empty entries list. Thank you!

Upvotes: 2

cannatag
cannatag

Reputation: 1588

you are not providing a username, so your connection is anonymous. Try accessing with username="myname", password="mypassword" in the connection object. You can also try NTLM authentication with authentication=NTLM. (You must import NTLM from the ldap3 package). In this case username must be "mydomain//myname".

Upvotes: 1

Mike Shlanta
Mike Shlanta

Reputation: 168

Shot in the dark, but try removing the parentheses around the query so (givenName=Charles) becomes givenName=Charles. Are you sure the domain components are correct?

Upvotes: 1

Related Questions