python base64解码TypeError: Incorrect padding错误

直接贴代码
>>> b='5paw5Lqn5ZOB55qE5biC5Zy6 566h55CGMWk'
>>> base64.b64decode(b)
Traceback (most recent call last):
  File "", line 1, in
  File "/usr/lib64/python2.6/base64.py", line 76, in b64decode
    raise TypeError(msg)
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 

你可能感兴趣的:(python,base,解码)