使用Active Directory自动填写员工姓名

时间:2019-04-20 15:36:54

标签: python-3.x autocomplete active-directory autosuggest pyad

要求:我正在尝试为前端Web表单创建自动完成/自动建议功能。在后端,有一个Python函数可以查询Active目录。

问题LIKE运算符在pyad.adquery -> execute_query -> where_clause中不起作用

在PyAD v 0.4.x中,我看到以下示例使用(cn like 'ws%'):

q = pyad.adquery.ADQuery()
q.execute_query(
        attributes = ['distinguishedname', 'description'],
        where_clause = "cn like 'ws%'",
        base_dn = "dc=company,dc=com"
)
for r in q.get_results():
        print r['distinguishedname']

但是当我使用LIKE运算符时,我得到:

>>> import pyad.adquery
>>> q = pyad.adquery.ADQuery()
>>> q.execute_query(attributes=["displayName"], where_clause="cn = 'Kent'", base_dn="OU=def,DC=abc,DC=com")
>>> q.execute_query(attributes=["displayName"], where_clause="cn like 'Kent%'", base_dn="OU=def,DC=abc,DC=com")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "D:\Users\Kent\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 "D:\Users\Kent\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, 'Provider', 'One or more errors occurred during processing of command.', None, 1240640, -2147217900), None)
>>>

我已经安装了v 0.6.0,但缺少LIKEwhere_clause的示例,但是当我查看Python软件包文件(\ Python37 \ Lib \ site-packages \ pyadadquery.py [在def execute_query()中,我看不出它不再起作用的任何原因。

0 个答案:

没有答案