python base64解码TypeE

发布时间:2019-08-26 07:20:06编辑:auto阅读(2098)

    直接贴代码
    >>> b='5paw5Lqn5ZOB55qE5biC5Zy6566h55CGMWk'
    >>> 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

    百度了一下找到国外的一篇文章
    解决办法如下:
      lens = len(strg) lenx = lens - (lens % 4 if lens % 4 else 4) try:     result = base64.decodestring(strg[:lenx]) except etc 

关键字