python base64解码TypeE
直接贴代码 File "", line 1, in File "/usr/lib64/python2.6/base64.py", line 76, in b64decode raise TypeError(msg)
>>> b='5paw5Lqn5ZOB55qE5biC5Zy6 566h55CGMWk'
>>> base64.b64decode(b)
Traceback (most recent call last):
TypeError: Incorrect padding
百度了一下找到国外的一篇文章
Http://stackoverflow.com/questions/2941995/Python-ignore-incorrect-padding-error-when-base64-decoding
解决办法如下:
lens = len(strg) lenx = lens - (lens % 4 if lens % 4 else 4) try: result = base64.decodestring(strg[:lenx]) except etc
相关文章