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 婆婆高寿祝福语大全简短