关于不完整的base64编码,导致的报错问题
报错1:
Error: Incorrect padding # base64编码不完整
报错2:
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 99-100: invalid continuation byte # utf-8编码中还有不可识别的编码
#!usr/bin/env python # coding:utf-8 import base64 import chardet s = b'5Y+v5Lul6K+05piv5peg5omA5LiN6IO977yM57G75Ly85LqO5L2g5bey57uP6Kej5byA6L+Z5Liq5Yqg5a+G77yM5Zyo6L+Z5Liq6L+H56iL5Lit77yM5L2g5bCx6IO95piO55**77yM6buR5a6i5Zyo6Ieq5bex5omA5o6M5o+h55qE5oqA5pyv5LmL5YaF77yM5Y+v5Lul5YGa5b6I5aSa5LqL5oOF' missing_padding = 4 - len(s) % 4 # 解决不完整编码问题 if missing_padding: s += b'=' * missing_padding b = base64.b64decode(s) print(str(b, "utf-8", "ignore")) # "ignore" 解决混杂其他编码问题