Getting AttributeError: module 'base64' has no attribute 'decodestring' error while running on python 3.9.6

Viewed 13730

Issue description:

Getting AttributeError: module 'base64' has no attribute 'decodestring' error while running on python 3.9.6

Steps to reproduce:

Below is a dummy program, while running on python 3.9.6, I am getting `AttributeError: module 'base64' has no attribute 'decodestring'`` error:

from ldif3 import LDIFParser

parser = LDIFParser(open('dse3.ldif', 'rb'))
for dn, entry in parser.parse():
    if dn == "cn=Schema Compatibility,cn=plugins,cn=config":
        if entry['nsslapd-pluginEnabled'] == ['on']:
            print('Entry record: %s' % dn)

Error message:

python3.9 1.py                              ✔    venvpy3.9   11:12:01 
Traceback (most recent call last):
  File "/Users/rasrivas/local_test/1.py", line 4, in <module>
    for dn, entry in parser.parse():
  File "/Users/rasrivas/local_test/venvpy3.9/lib/python3.9/site-packages/ldif3.py", line 384, in parse
    yield self._parse_entry_record(block)
  File "/Users/rasrivas/local_test/venvpy3.9/lib/python3.9/site-packages/ldif3.py", line 357, in _parse_entry_record
    attr_type, attr_value = self._parse_attr(line)
  File "/Users/rasrivas/local_test/venvpy3.9/lib/python3.9/site-packages/ldif3.py", line 315, in _parse_attr
    attr_value = base64.decodestring(line[colon_pos + 2:])
AttributeError: module 'base64' has no attribute 'decodestring'

python version

python --version 
Python 3.9.6

Operating system:

macOS 11.5.2

Python version:

python --version 
Python 3.9.6

python-ldap version:

ldif3-3.2.2

4 Answers

From the docs for Python 3.8, base64.decodestring() is described as a:

Deprecated alias of decodebytes().

It looks like the base64.decodestring() function has been deprecated since Python 3.1, and removed in Python 3.9. You will want to use the bas64.decodebytes() function instead.

This is an old post but I am leaving here in case someone stumbles upon the same question.

To decode base64 to bytes use base64.b64decode()

You can find more info here

Try install base64 in your python, use the command:

pip install pybase64

or:

pip3 install pybase64
Related