手机
当前位置:查字典教程网 >脚本专栏 >python >python base64 decode incorrect padding错误解决方法
python base64 decode incorrect padding错误解决方法
摘要:python的base64.decodestring方法做base64解码时报错:复制代码代码如下:Traceback(mostrecent...

python的base64.decodestring方法做base64解码时报错:

复制代码 代码如下:

Traceback (most recent call last):

File "/export/www/outofmemory.cn/controllers/user.py", line 136, in decryptPassword

encryptPwd = base64.b64decode(encryptPwd)

File "/usr/lib/python2.7/base64.py", line 76, in b64decode

raise TypeError(msg)

TypeError: Incorrect padding

这也算是python的一个坑吧,解决此问题的方法很简单,对base64解码的string补齐等号就可以了,如下代码:

复制代码 代码如下:

def decode_base64(data):

"""Decode base64, padding being optional.

:param data: Base64 data as an ASCII byte string

:returns: The decoded byte string.

"""

missing_padding = 4 - len(data) % 4

if missing_padding:

data += b'='* missing_padding

return base64.decodestring(data)

【python base64 decode incorrect padding错误解决方法】相关文章:

python解决字典中的值是列表问题的方法

python中使用sys模板和logging模块获取行号和函数名的方法

python中的sort方法使用详解

Python中的魔法方法深入理解

python新手经常遇到的17个错误分析

python读取注册表中值的方法

Python linecache.getline()读取文件中特定一行的脚本

Python字符串的encode与decode研究心得乱码问题解决方法

Python中的Function定义方法第1/2页

python解析html开发库pyquery使用方法

精品推荐
分类导航