Skip to content

Example in documentation does not work #306

@robert-sherwood

Description

@robert-sherwood

If you found a bug in python-ldap, or would request a new feature,
this is the place to let us know.

Please describe the issue and your environment here.


Issue description:
Example at the following link:
https://github.com/python-ldap/python-ldap/blob/master/Doc/reference/ldif.rst#example

import sys,ldif
entry={'objectClass':['top','person'],'cn':['Michael Stroeder'],'sn':['Stroeder']}
dn='cn=Michael Stroeder,ou=Test'
ldif_writer=ldif.LDIFWriter(sys.stdout)
ldif_writer.unparse(dn,entry)

When entering this code in the python console, the following error is received:
Traceback (most recent call last):
File "", line 1, in
File "/Users/plainid/PycharmProjects/LDIF_Generator/venv/lib/python3.7/site-packages/ldif.py", line 198, in unparse
self._unparseEntryRecord(record)
File "/Users/plainid/PycharmProjects/LDIF_Generator/venv/lib/python3.7/site-packages/ldif.py", line 155, in _unparseEntryRecord
self._unparseAttrTypeandValue(attr_type,attr_value)
File "/Users/plainid/PycharmProjects/LDIF_Generator/venv/lib/python3.7/site-packages/ldif.py", line 139, in _unparseAttrTypeandValue
if self._needs_base64_encoding(attr_type,attr_value):
File "/Users/plainid/PycharmProjects/LDIF_Generator/venv/lib/python3.7/site-packages/ldif.py", line 128, in _needs_base64_encoding
not safe_string_re.search(attr_value) is None
TypeError: cannot use a bytes pattern on a string-like object

Steps to reproduce:
Enter example from documentation in python console

Fix is simple, mark the entry attribute strings as bytestrings:
entry={"objectClass":[b"top",b"person"],"cn":[b"Michael Stroeder"],"sn":[b"Stroeder"]}

Operating system:
Mac OS
Python version:
3.7
python-ldap version:
3.2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy