python3 base64加密第一种写法(通过字符串提取)
#方法一
import base64
a = 'testzifuchuan'
jm = base64.b64encode(a.encode('utf-8'))
b = str(jm)
print(b[2:-1])
输出结果
对于python3,你如果写成了python2的那种语法,你会得到报错,因为在python3里面是字节流,不是字符串,你得转换成字符串进行操作
python3 base64加密第二种写法(直接转换操作)
import base64
a = 'testzifuchuan'
d = base64.b64encode(a.encode('utf-8'))
print(str(d,'utf-8'))
python2 base64加密
import base64
a = 'testzifuchuan'
jm = base64.b64encode(a)
print jm
print type(jm)
输出结果: