2016-11-18 6 views
0

私のldap3での最初の経験は計画どおりではありません。これが機能しない理由私は十分に簡単なようだhttp://ldap3.readthedocs.io/abstraction.htmlPython ldap3リーダーコールが失敗する

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呼び出しで塊を吹き飛ばします。ここでは、コードスニペットがあります:

condaリスト毎の
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' 

ldap3      1.0.4     py35_0` 

私はここで何をしないのですか?

+0

'person_reader.search()'を呼び出すまでになっていますか?コードサンプルにnoと表示されます。 –

+0

参考:Anaconda Pythonバージョン3.5.2を使用しています – Harvey

+0

また、「人」とは何ですか?それは未定義のようです。 –

答えて

0

人への第2引数は()である:

definition: the ObjectDef used by the Reader instance.

REF:http://ldap3.readthedocs.io/abstraction.html

あなたはで合格するObjectDefを作成する必要があり、これはユーザーIDではありません。これは、読み取る必要のあるオブジェクトタイプの定義です。

person = ObjectDef(['person','user'], conn) 
r = Reader(conn, person, base, query) 

私は、完全修飾ベースDN以外のものとして、人への第三引数を渡す任意の経験を持っていない:あなたは好きで、それを使用する場合があります。したがって、ou = testが登録されたbaseDnでない場合、これはLDAP(AD)インスタンスでは機能しない可能性があります。

0

壁に何かを投げつけた後も、私はすべての開発者がツールを使用して何をしているのか - 最初から始めて、あなたが話したことのすべてを捨てます。そして、解決策だった:

は、ユーザ認証を削除し、匿名で

電話をかけるはい、でも認証がそれを使用するために必要なかった、私はコールへのアクセスを取得するために、セキュリティのフープを介してジャンプすると思っていました。ええ、私たちはただ幸せになり、次のように進むでしょう。それに住んでいないでください。

関連する問題