获取AttributeError:模块'base64'有没有属性'decodestring'错误,而运行在Python 3.9.6上

axzmvihb  于 2023-06-25  发布在  Python
关注(0)|答案(5)|浏览(61)

问题描述:
在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

wgx48brx

wgx48brx1#

在Python 3.8的文档中,base64.decodestring()被描述为:
decodebytes()的别名已弃用。
看起来base64.decodestring()函数自Python 3.1以来就被弃用了,并在Python 3.9中被删除了。您可能需要使用bas64.decodebytes()函数。

9nvpjoqh

9nvpjoqh2#

decodestring()从v3.9不再存在。 checkout 这个文档,使用base64.decodebytes()代替

nwsw7zdq

nwsw7zdq3#

这是一个老职位,但我离开这里,以防有人绊倒同样的问题。
使用base64.b64decode()将base64解码为字节
您可以找到更多信息here

l7mqbcuq

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)
试着

  1. pip install pybase64
  2. pip3安装pybase64但不能工作enter image description here
ax6ht2ek

ax6ht2ek5#

尝试在python中安装base64,使用命令:

pip install pybase64

或:

pip3 install pybase64

相关问题