简体   繁体   中英

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.

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!

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?

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" .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM