问题描述:
在Python 3.9.6上运行时出现AttributeError: module 'base64' has no attribute 'decodestring'
错误
复制步骤:
下面是一个虚拟程序,在python 3.9.6上运行时,我得到了AttributeError:模块'base64'没有属性'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版本
python --version
Python 3.9.6
操作系统:
macOS 11.5.2
Python版本:
python --version
Python 3.9.6
python-ldap版本:ldif3-3.2.2
5条答案
按热度按时间wgx48brx1#
在Python 3.8的文档中,
base64.decodestring()
被描述为:decodebytes()的别名已弃用。
看起来
base64.decodestring()
函数自Python 3.1以来就被弃用了,并在Python 3.9中被删除了。您可能需要使用bas64.decodebytes()
函数。9nvpjoqh2#
decodestring()
从v3.9不再存在。 checkout 这个文档,使用base64.decodebytes()代替nwsw7zdq3#
这是一个老职位,但我离开这里,以防有人绊倒同样的问题。
使用
base64.b64decode()
将base64解码为字节您可以找到更多信息here
l7mqbcuq4#
File "/home/jibon/odoo-13.0/lib/python3.10/site-packages/reportlab/lib/utils. py ",line 8,in from base64 import decodestring as base64_decodestring,encodestring as base64_encodestring ImportError:无法从'base64'导入名称'decodestring'(/usr/lib/python3.10/base64.py)
试着
ax6ht2ek5#
尝试在python中安装base64,使用命令:
或: