python base64 decode incorrect padding错误解决方法
python的base64.decodestring方法做base64解码时报错:
Traceback(mostrecentcalllast): File"/export/www/outofmemory.cn/controllers/user.py",line136,indecryptPassword encryptPwd=base64.b64decode(encryptPwd) File"/usr/lib/python2.7/base64.py",line76,inb64decode raiseTypeError(msg) TypeError:Incorrectpadding
这也算是python的一个坑吧,解决此问题的方法很简单,对base64解码的string补齐等号就可以了,如下代码:
defdecode_base64(data):
"""Decodebase64,paddingbeingoptional.
:paramdata:Base64dataasanASCIIbytestring :returns:Thedecodedbytestring.
""" missing_padding=4-len(data)%4 ifmissing_padding: data+=b'='*missing_padding returnbase64.decodestring(data)
热门推荐
10 感谢韩语老师祝福语简短
11 升职文案高级祝福语简短
12 花童结婚祝福语大全简短
13 向国庆送祝福语简短
14 什么寄语简短祝福语女生
15 客户回礼祝福语大全简短
16 女孩生日祝福语简短创意
17 家长回复节日祝福语简短
18 给外婆敬酒祝福语简短