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

4

13

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

Guereza answered 15/9, 2021 at 5:48 Comment(0)
A
30

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.

Archimandrite answered 15/9, 2021 at 5:56 Comment(1)
Hi @BillyBBone, I happen to get the same error, just with encoding instead of decoding a string, and it doesn't let me change that to bytes instead of string. I get the below error - "TypeError: memoryview: a bytes-like object is required, not 'str'"Magalymagan
K
6

decodestring() no longer exists from v 3.9. Checkout this docs, use base64.decodebytes() instead

Keary answered 30/3, 2022 at 16:1 Comment(0)
P
4

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

Peloquin answered 27/12, 2021 at 21:17 Comment(0)
P
-3

Try install base64 in your python, use the command:

pip install pybase64

or:

pip3 install pybase64
Pinkeye answered 15/9, 2021 at 5:53 Comment(1)
Thanks for the comment, but still I am getting the same error: pip3 install pybase64 --> Requirement already satisfied: pybase64 in ./venvpy3.9/lib/python3.9/site-packages (1.2.0) ==> error message AttributeError: module 'base64' has no attribute 'decodestring'Guereza

© 2022 - 2024 — McMap. All rights reserved.