Python Forum
Ldap3 Python print(conn.entries) doesnt work
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ldap3 Python print(conn.entries) doesnt work
#11
(Mar-15-2022, 12:42 PM)Gribouillis Wrote: What is the type of CaseInsensitiveDict ?

it is a library
Reply
#12
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)
{}
Reply
#13
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?
Reply
#14
I wonder how the line import CaseInsensitiveDict can succeed. Do you have such a module?
Reply
#15
Yes I have such a library.
Reply
#16
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)
Output:
DN: uid=admin,cn=users,cn=accounts,dc=demo1,dc=freeipa,dc=org krbLastPwdChange: 2016-10-09 10:01:18+00:00 objectclass: top person posixaccount krbprincipalaux krbticketpolicyaux inetuser ipaobject ipasshuser ipaSshGroupOfPubKeys sn: Administrator
Yoriz write Dec-28-2022, 11:49 AM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  print doesnt work in a function ony 2 314 Mar-11-2024, 12:42 PM
Last Post: Pedroski55
  Pydoc documentation doesnt work Cosmosso 5 4,396 Nov-25-2023, 11:17 PM
Last Post: vidito
  sqlite3 Conn Insert Value Error TylerDunbar 3 755 Sep-04-2023, 06:32 PM
Last Post: deanhystad
  pip install requests doesnt work misodca 8 6,189 Jul-07-2023, 08:04 AM
Last Post: zyple
  pip install pystyle doesnt work person_probably 2 2,125 Sep-23-2022, 02:59 PM
Last Post: person_probably
  Why doesnt chunk generation work? LotosProgramer 1 1,953 Apr-02-2022, 08:25 AM
Last Post: deanhystad
  if conditions in the for indentation doesnt work ? Sutsro 6 3,951 Jun-15-2021, 11:45 PM
Last Post: bowlofred
  Why doesn't this print statement work? stylingpat 10 5,779 Mar-23-2021, 07:54 PM
Last Post: buran
  I have two Same Code but One of them Doesnt Work beginner721 6 3,101 Jan-22-2021, 10:56 PM
Last Post: beginner721
  Python to Oracle Conn Issue chvsnarayana 2 39,799 Sep-06-2020, 04:33 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020