Pyad connection to another server

1k Views Asked by At

Can someone help me to solve my issue? I try to download some user-info from server's active directory. When I tried that without pyad_setdefaults - that's ok. But when I try to connect to another server -I have an error.

import pyad
import pyad.adquery
pyad.pyad_setdefaults(ldap_server= 'myserv', username= 'login', password= 'pass'
q = pyad.adquery.ADQuery()
attributes = ['SamAccountName']
q.execut_equery(attributes= attributes)
result= q.get_all_results()

And i have this error: enter image description here

I tried pyad.pyad.set_defaults - there were the same error. My server has a connection to another. And this account has an acces to AD.

1

There are 1 best solutions below

0
On

I figured out. If you want to use adquery , you need to set default server:

import pyad
import pyad.adquery
q = pyad.adquery.ADQuery()
attributes = ['SamAccountName']
q.default_ldap_server = server_address
q.default_username = user_login
q.default_password = user_password
q.execute_query(attributes= attributes)
result= q.get_all_results()

Sometimes you need to indicate base_dn in execute_query.