python中Base64编码和解码:TypeError: a bytes-like object is required, not 'str'

在目前最新版本下出现问题

F:\p>python

Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AM
D64)] on win32

Type "help", "copyright", "credits" or "license" for more information.



#-*- coding: utf-8 
import base64

str='cnblogs'
str64=base64.b64encode(str)
print(str64)           #Y25ibG9ncw==
print(base64.b64decode(str64))   #cnblogs

正确修改 str=b'cnblogs'                           

 就能解决问题。

你可能感兴趣的:(python)