[python-ldap] search output as ldif in a file

Vikram NS vikramns at gmail.com
Thu Jul 19 08:56:34 EDT 2018


Hi Folks,

Thanks in advance on helping me out

I am doing a bulk search and hoping to build a LDIF file with the results,
following is the code snippet

try:
    entries = lw_conn.extend.standard.paged_search(search_base=base_dn,

search_filter=lw_filter,
                                                           search_scope=SUBTREE,

attributes=retrive_attrs,
                                                           paged_size=page_size,
                                                           generator=True)
except Exception as e:
    sys.exit("Search failed: %s" % e)

ldif_writer = LDIFWriter(open(args.write,'wb'), base64_attrs=None, cols=160)
for entry in entries:
    entry['raw_attributes'].pop('nTSecurityDescriptor')
    ldif_writer.unparse(entry['dn'], entry['raw_attributes'])


Getting the following error:
Traceback (most recent call last):
  File "./ldap_export.py", line 111, in <module>
    ldif_writer.unparse(entry['dn'], entry['attributes'])
  File
"/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/ldif3.py",
line 199, in unparse
    raise ValueError("Argument record must be dictionary or list")
ValueError: Argument record must be dictionary or list

Tried converting entry['attributes'] into a dictionary, with that LDIFWrite
worked but all the attributes got encoded in base64, base64_attrs=None
didn't help

cn:: VmlrcmFtIE4gUw==

Thanks,
Vikram
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ldap/attachments/20180719/c6df33c4/attachment.html>


More information about the python-ldap mailing list