python base64 decode incorrect padding錯(cuò)誤解決方法
python的base64.decodestring方法做base64解碼時(shí)報(bào)錯(cuò):
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的一個(gè)坑吧,解決此問(wèn)題的方法很簡(jiǎn)單,對(duì)base64解碼的string補(bǔ)齊等號(hào)就可以了,如下代碼:
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中__add__函數(shù)的用法
- Python使用add_subplot與subplot畫(huà)子圖操作示例
- python中g(shù)etaddrinfo()基本用法實(shí)例分析
- Python socket.error: [Errno 98] Address already in use的原因和解決方法
- python構(gòu)造函數(shù)init實(shí)例方法解析
- python matplotlib中的subplot函數(shù)使用詳解
- Python實(shí)現(xiàn)計(jì)算長(zhǎng)方形面積(帶參數(shù)函數(shù)demo)
- 解決python replace函數(shù)替換無(wú)效問(wèn)題
- python add_argument()用法解析
相關(guān)文章
在?pytorch?中實(shí)現(xiàn)計(jì)算圖和自動(dòng)求導(dǎo)
這篇文章主要介紹了在?pytorch?中實(shí)現(xiàn)計(jì)算圖和自動(dòng)求導(dǎo),文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-06-06
pytorch中關(guān)于distributedsampler函數(shù)的使用
二種python發(fā)送郵件實(shí)例講解(python發(fā)郵件附件可以使用email模塊實(shí)現(xiàn))
Python讀取Excel數(shù)據(jù)并生成圖表過(guò)程解析
Python 循環(huán)終止語(yǔ)句的三種方法小結(jié)
python中opencv K均值聚類的實(shí)現(xiàn)示例
Django高級(jí)編程之自定義Field實(shí)現(xiàn)多語(yǔ)言

