python base64 decode incorrect padding错误解决方法
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)
相关推荐
pythonjw 2020-11-17
hedongli 2020-09-01
浪味仙 2020-08-17
IT兄弟团 2020-08-01
凉白开 2020-07-19
kjh00abc 2020-07-08
Skyline 2020-06-28
苦咖啡flask 2020-06-18
万物weiyi 2020-06-16
半纸药笺 2020-06-14
chenhaimeimeng 2020-06-13
JF0 2020-06-13
逍遥友 2020-06-02
kyelu 2020-06-02
northwindx 2020-05-31
tengyuan 2020-05-30
singer 2020-05-30
GreatZhou 2020-05-28
coolhty 2020-05-20