所以我第一次使用ldap3的体验并没有按计划进行。我搞不懂为什么这不管用。
来自http://ldap3.readthedocs.io/abstraction.html的代码示例
s = Server('server')
c = Connection(s, user = 'username', password = 'password')
query = 'Department: Accounting' # explained in next paragraph
person_reader = Reader(c, person, 'o=test', query)
person_reader.search()这看起来很简单。但是,我的代码在Server和Connection调用中运行良好,却在Reader调用中破坏了块。下面是代码片段:
query = 'department: Security Risk'
person_reader = Reader(c, person, 'OU=All Businesses', query)以及令人不快的结果
AttributeError Traceback (most recent call last)
in ()
1 query = 'department: Security Risk'
----> 2 person_reader = Reader(c, person, 'OU=All Businesses', query)
C:\Users########\AppData\Local\Continuum\Anaconda3\lib\site-packages\ldap3\abstract\reader.py in init(self, connection, object_def, query, base, components_in_and, sub_tree, get_operational_attributes, controls)
79 self.base = base
80 self._components_in_and = components_in_and
---> 81 self.attributes = sorted([attr.name for attr in self._definition])
82 self.get_operational_attributes = get_operational_attributes
83 self.controls = controls
C:\Users##########\AppData\Local\Continuum\Anaconda3\lib\site-packages\ldap3\abstract\reader.py in (.0)
79 self.base = base
80 self._components_in_and = components_in_and
---> 81 self.attributes = sorted([attr.name for attr in self._definition])
82 self.get_operational_attributes = get_operational_attributes
83 self.controls = controls
AttributeError: 'str' object has no attribute 'name'每个conda列表:
ldap3 1.0.4 py35_0`这里我漏掉了什么?
发布于 2017-02-14 23:52:23
Person()的第二个参数是:
定义:阅读器实例使用的ObjectDef。
参考:http://ldap3.readthedocs.io/abstraction.html
您必须创建一个ObjectDef来传入,这不是一个userid。这是应该读取的对象类型的定义。您可以像这样使用它:
person = ObjectDef(['person','user'], conn)
r = Reader(conn, person, base, query)除了将第三个参数作为完全限定的基本DN传递给Person之外,我没有任何经验。因此,如果ou=test不是已注册的baseDn,这在您的LDAP(AD)实例中可能不起作用。
发布于 2017-02-28 05:56:51
因此,在把所有东西都扔到墙上,没有任何粘连之后,我做了每个没有工具的开发人员都会做的事情-从头开始,扔掉你被告知的一切。解决方案是:
删除用户身份验证并匿名进行呼叫
是的,即使我必须跳过安全圈才能访问呼叫,使用它也不需要身份验证。是啊,我们会很开心然后继续生活。不要纠结于此。
https://stackoverflow.com/questions/40683936
复制相似问题