Mar-15-2022, 12:43 PM
Ldap3 Python print(conn.entries) doesnt work
Ldap3 Python print(conn.entries) doesnt work
|
Mar-15-2022, 12:48 PM
It works very well for me, how do you import CaseInsensitiveDict? Try this code in the Python console
>>> from ldap3.utils.ciDict import CaseInsensitiveDict >>> type(CaseInsensitiveDict) <class 'abc.ABCMeta'> >>> d = CaseInsensitiveDict() >>> isinstance(d, CaseInsensitiveDict) True >>> dict(d) {}
Mar-15-2022, 12:59 PM
result = (True, {'result': 0, 'description': 'success', 'dn': '', 'message': '', 'referrals': None, 'type': 'searchResDone'}, [{'raw_dn': b'CN=user G\xc3\xbc\xc3\xa7l\xc3\xbc,OU=DEVELOPERS,OU=ANKARA,OU=TURKIYE,OU=TRD-GLOBAL,DC=TRD,DC=local', 'dn': 'CN=User1,OU=DEVELOPER,OU=ANKARA,OU=TURKIYE,OU=TRD-GLOBAL,DC=TRD,DC=local', 'raw_attributes': {}, 'attributes': {}, 'type': 'searchResEntry'}, {'uri': ['ldap://ForestDnsZones.TRD.local/DC=ForestDnsZones,DC=TRD,DC=local'], 'type': 'searchResRef'}, {'uri': ['ldap://DomainDnsZones.TRD.local/DC=DomainDnsZones,DC=TRD,DC=local'], 'type': 'searchResRef'}, {'uri': ['ldap://TRD.local/CN=Configuration,DC=TRD,DC=local'], 'type': 'searchResRef'}], {'base': 'dc=my,dc=server', 'scope': 2, 'dereferenceAlias': 3, 'sizeLimit': 0, 'timeLimit': 0, 'typesOnly': False, 'filter': '(sAMAccountName=user1)', 'attributes': ['1.1'], 'type': 'searchRequest', 'controls': None}) from ldap3 import Server, Connection, ALL from ldap3 import Server, Connection, SAFE_SYNC import json import functools import CaseInsensitiveDict from ldap3.utils.ciDict import CaseInsensitiveDict class MyEncoder(json.JSONEncoder): def default(self, obj): if isinstance(obj, bytes): obj = str(obj, encoding='utf-8') elif isinstance(obj, CaseInsensitiveDict): obj = dict(obj) return json.JSONEncoder.default(self, obj) s = json.dumps(result, cls=MyEncoder, indent=4) print(s)Is it false?
Mar-15-2022, 01:42 PM
I wonder how the line
import CaseInsensitiveDict can succeed. Do you have such a module?
Mar-16-2022, 08:31 AM
Yes I have such a library.
Dec-28-2022, 11:22 AM
(This post was last modified: Dec-28-2022, 11:49 AM by Yoriz.
Edit Reason: Added code tags
)
entries will be filled when connection invoked within with statement like below.with Connection(server, 'uid=admin,cn=users,cn=accounts,dc=demo1,dc=freeipa,dc=org', 'Secret123') as conn: conn.search('dc=demo1,dc=freeipa,dc=org', '(&(objectclass=person)(uid=admin))', attributes=['sn','krbLastPwdChange', 'objectclass']) entry = conn.entries print(entry)
|
|
Users browsing this thread: 1 Guest(s)