如何在运行String decode()方法时修复python3中的LookupError:base64

如何在运行String decode()方法时修复python3中的LookupError:base64,python,string,python-3.x,utf-8,decode,Python,String,Python 3.x,Utf 8,Decode,我正在python3中运行下面的程序,但出现了一个错误 Str = "this is string example....wow!!!"; Str = Str.encode('base64','strict'); print ("Encoded String: " + Str) print ("Decoded String: " + Str.decode('base64','strict')) 得到的错误是:- File "learn.py", line 646, in <module&

我正在python3中运行下面的程序,但出现了一个错误

Str = "this is string example....wow!!!";
Str = Str.encode('base64','strict');
print ("Encoded String: " + Str)
print ("Decoded String: " + Str.decode('base64','strict'))
得到的错误是:-

File "learn.py", line 646, in <module>
    Str = Str.encode('base64','strict');
LookupError: 'base64' is not a text encoding; use codecs.encode() to handle arbitrary codecs
文件“learn.py”,第646行,在
Str=Str.encode('base64','strict');
LookupError:“base64”不是文本编码;使用codecs.encode()处理任意编解码器

Base64不是一种字符串编码方法,它是一种字节编码方法,而是使用编码和解码
Base64
(使用多于所需的变量,以便每个人都可以跟踪操作)


您是否尝试实现错误消息告诉您的操作?另外,为什么不直接使用
base64
模块?是的,我刚才尝试了base64模块,但没有达到预期效果output@MartijnPieters是的,兄弟,我试过了,但也犯了同样的错误。不过,你的问题中没有包含这些信息。你检查了吗?亲爱的,你能告诉我如何在上面的程序中使用base64模块吗
import base64
print("base64 Encoded/Decoded string \n")
str="this is a test string "
s1=str.encode('ascii')  # it will result like: b'this is a test string'
s2=base64.b64encode(s1);   #storing value before printing
print("encoded : ",s2)
print("decoded : ",base64.b64decode(s2)) #direct conversion