zakird / pyad

Python Active Directory Tools | *Not actively maintained*
http://zakird.github.io/pyad/
176 stars 72 forks source link

Having so much trouble with adquery? #111

Open patrickave opened 5 years ago

patrickave commented 5 years ago

Maybe I'm doing something dumb with the query but i even took a stripped down example to just test.

I'm already using pyad in my project and I have no issues thus far but when I try to query I keep getting this error.

from pyad import *
x = pyad.set_defaults(ldap_server="dc01.copper.local", username="administrator", password="labpw")
q = adquery.ADQuery()
q.execute_query(
    attributes = ["sAMAccountName"],
    where_clause = "objectClass = '*'",
    base_dn = 'CN=Users,OU=Lab,DC=copper,DC=local'
)

for row in q.get_results():
    print (row["sAMAccountName"])

Result:

Traceback (most recent call last):
  File "D:/adtest.py", line 11, in <module>
    base_dn = 'CN=Users,OU=Lab,DC=copper,DC=local'
  File "AppData\Local\Programs\Python\Python37\lib\site-packages\pyad\adquery.py", line 78, in execute_query
    self.__rs, self.__rc = command.Execute()
  File "<COMObject ADODB.Command>", line 3, in Execute
  File "AppData\Local\Programs\Python\Python37\lib\site-packages\win32com\client\dynamic.py", line 287, in _ApplyTypes_
    result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Active Directory', 'The server is not operational.\r\n', None, 0, -2147217865), None)

Process finished with exit code 1
aimalkhan commented 5 years ago

seeing the exact same issue on q = adquery.ADQuery()

This code snippet is from the project Readme. May be something broke due to a recent change?

krabat1987 commented 5 years ago

I see the same issue on adding/deleting members to AD groups. ad_group.add_members(users_to_add) => also (slightly modified) from the readme. I installed pyad about 2 months ago and didn't need/was not able to use that feature since.

EDIT: before I forget about that: iterating over the members of a group works for me.

mattburlage commented 3 years ago

I'm getting this error too, but not when using something like aduser.ADUser.from_dn(dn)

richardjprice commented 3 years ago

Same as above, I cannot import any of the search functions as I'll get a pywintypes.com_error - What is the proper way to use adsearch?