在 python 3.9.6 上运行时出现 AttributeError: module 'base64' has no attribute 'decodestring' 错误

Rah*_*ava 13 python ldap ldif python-3.x

问题描述:

\n

AttributeError: module 'base64' has no attribute 'decodestring'在 python 3.9.6 上运行时出现错误

\n

重现步骤:

\n

下面是一个虚拟程序,在 python 3.9.6 上运行时,我收到 `AttributeError: module 'base64' has no attribute 'decodestring'`` 错误:

\n
from ldif3 import LDIFParser\n\nparser = LDIFParser(open('dse3.ldif', 'rb'))\nfor dn, entry in parser.parse():\n    if dn == "cn=Schema Compatibility,cn=plugins,cn=config":\n        if entry['nsslapd-pluginEnabled'] == ['on']:\n            print('Entry record: %s' % dn)\n
Run Code Online (Sandbox Code Playgroud)\n

错误信息:

\n
python3.9 1.py                             \xee\x82\xb2 \xe2\x9c\x94 \xee\x82\xb3 \xef\x80\x93 \xee\x82\xb2 venvpy3.9 \xee\x9c\xbc \xee\x82\xb2 11:12:01 \xef\x80\x97\nTraceback (most recent call last):\n  File "/Users/rasrivas/local_test/1.py", line 4, in <module>\n    for dn, entry in parser.parse():\n  File "/Users/rasrivas/local_test/venvpy3.9/lib/python3.9/site-packages/ldif3.py", line 384, in parse\n    yield self._parse_entry_record(block)\n  File "/Users/rasrivas/local_test/venvpy3.9/lib/python3.9/site-packages/ldif3.py", line 357, in _parse_entry_record\n    attr_type, attr_value = self._parse_attr(line)\n  File "/Users/rasrivas/local_test/venvpy3.9/lib/python3.9/site-packages/ldif3.py", line 315, in _parse_attr\n    attr_value = base64.decodestring(line[colon_pos + 2:])\nAttributeError: module 'base64' has no attribute 'decodestring'\n
Run Code Online (Sandbox Code Playgroud)\n

蟒蛇版本

\n
python --version \nPython 3.9.6\n
Run Code Online (Sandbox Code Playgroud)\n

操作系统:

\n

macOS 11.5.2

\n

Python版本:

\n
python --version \nPython 3.9.6\n
Run Code Online (Sandbox Code Playgroud)\n

python-ldap 版本:

\n

ldif3-3.2.2

\n

Bil*_*one 28

Python 3.8 的文档中,base64.decodestring()被描述为:

不推荐使用decodebytes() 的别名。

看起来该base64.decodestring()函数自 Python 3.1 起已被弃用,并在 Python 3.9 中被删除。您将需要改用该bas64.decodebytes()函数。


小智 5

decodestring()从 v 3.9 开始不再存在。查看此文档,使用base64.decodebytes()代替