问题描述:
在 python 3.9.6 上运行时获取 AttributeError: module 'base64' has no attribute 'decodestring'
错误
重现步骤:
下面是一个虚拟程序,在 python 3.9.6 上运行时,出现“AttributeError: module ‘base64’ has no attribute ‘decodestring’”错误:
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)
错误信息:
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 3.9.6
操作系统:
macOS 11.5.2
蟒蛇版本:
python --version
Python 3.9.6
python-ldap 版本:
ldif3-3.2.2
原文由 Rahul Srivastava 发布,翻译遵循 CC BY-SA 4.0 许可协议
在 Python 3.8 的文档中,
base64.decodestring()
被描述为:看起来
base64.decodestring()
函数自 Python 3.1 以来已被弃用,并在 Python 3.9 中被删除。您将需要使用bas64.decodebytes()
函数。