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

 

相关文章:

  • 2021-09-13
  • 2021-12-21
  • 2022-12-23
  • 2021-09-26
  • 2022-12-23
  • 2021-05-06
  • 2022-12-23
  • 2021-07-20
猜你喜欢
  • 2022-12-23
  • 2021-07-02
  • 2021-12-26
  • 2021-12-26
  • 2021-12-10
  • 2022-12-23
  • 2021-11-24
相关资源
相似解决方案