base64,字符串文本编码解码,方便数据进行传输
1 import base64 2 '''编码解码''' 3 st = 'ni hao'.encode('utf8') 4 result = base64.b64encode(st) 5 print(result) # b'bmkgaGFv' 6 7 result = base64.b64decode(result) 8 print(result) # b'ni hao' 9 print(result.decode('utf8')) # ni hao 10 11 12 13 url = 'https://www.baidu.com'.encode('utf8') 14 result = base64.urlsafe_b64encode(url) 15 print(result) # b'aHR0cHM6Ly93d3cuYmFpZHUuY29t' 16 17 result = base64.urlsafe_b64decode(result) 18 print(result.decode('utf8')) # https://www.baidu.com