python Base64编码和解码
2022-05-23 本文已影响0人
孙广宁
6.10 使用base64对二进制数据进行编码和解码
- b64encode 函数对二进制进行编码
- .decode('ascii')函数来解码Unicode
>>> s = b'hello'
>>> import base64
>>> a =base64.b64encode(s)
>>> a
b'aGVsbG8='
>>> base64.b64decode(a)
b'hello'
>>> base64.b64decode(a).decode('ascii')
'hello'
>>>