mystr = "人生苦短,我用Python"
mystr = bytes(mystr,encoding="utf-8") ==需加这一行代码即可
a = base64.b64encode(mystr)
python3.x中字符都为unicode编码,而b64encode函数的参数为byte类型,所以必须先转码。
转码可以使用encode()函数,也可以使用bytes函数,如bytes(usr_pwd,encoding = ‘utf-8’)和usr_pwd.encode(‘utf-8’)二者效果是一样的!