Rah*_*ava 13 python ldap ldif python-3.x
问题描述:
\nAttributeError: module 'base64' has no attribute 'decodestring'在 python 3.9.6 上运行时出现错误
重现步骤:
\n下面是一个虚拟程序,在 python 3.9.6 上运行时,我收到 `AttributeError: module 'base64' has no attribute 'decodestring'`` 错误:
\nfrom 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)\nRun Code Online (Sandbox Code Playgroud)\n错误信息:
\npython3.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'\nRun Code Online (Sandbox Code Playgroud)\n蟒蛇版本
\npython --version \nPython 3.9.6\nRun Code Online (Sandbox Code Playgroud)\n操作系统:
\nmacOS 11.5.2
\nPython版本:
\npython --version \nPython 3.9.6\nRun Code Online (Sandbox Code Playgroud)\npython-ldap 版本:
\nldif3-3.2.2
Bil*_*one 28
从Python 3.8 的文档中,base64.decodestring()被描述为:
不推荐使用decodebytes() 的别名。
看起来该base64.decodestring()函数自 Python 3.1 起已被弃用,并在 Python 3.9 中被删除。您将需要改用该bas64.decodebytes()函数。