看评论区,才弄懂的
import base64def safe_base64_decode(s): x = 0 # s若不是4的倍数,则肯定被去掉[4-len(s)%4]个'=' if len(s)%4: x = 4-len(s)%4 # 将去掉的'='的补上 s = s+'='*x return base64.b64decode(s)assert b'abcd' == safe_base64_decode('YWJjZA=='), safe_base64_decode('YWJjZA==')assert b'abcd' == safe_base64_decode('YWJjZA'), safe_base64_decode('YWJjZA')print('ok')
Sign in to make a reply
这是QQ昵称
看评论区,才弄懂的