繁体   English   中英

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

[英]how to fix LookupError: base64 in python3 while running String decode() Method

我正在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

Base64不是字符串编码方法,它的一种字节编码方法使用base64模块代替

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM