如何在python3中解码base64 [英] How to decode base64 in python3

查看:421
本文介绍了如何在python3中解码base64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个base64加密代码,并且无法在python3.5中解码

I have a base64 encrypt code, and I can't decode in python3.5

import base64
code = "YWRtaW46MjAyY2I5NjJhYzU5MDc1Yjk2NGIwNzE1MmQyMzRiNzA" # Unencrypt is 202cb962ac59075b964b07152d234b70
base64.b64decode(code)

结果:

binascii.Error: Incorrect padding

但是同一网站( base64decode )可以对其进行解码,

But same website(base64decode) can decode it,

请任何人都可以告诉我原因,以及如何使用python3.5对其进行解码?

Please anybody can tell me why, and how to use python3.5 decode it?

谢谢

推荐答案

Base64需要一个长度倍数为4的字符串.如果该字符串很短,则用1到3 =填充.

Base64 needs a string with length multiple of 4. If the string is short, it is padded with 1 to 3 =.

import base64
code = "YWRtaW46MjAyY2I5NjJhYzU5MDc1Yjk2NGIwNzE1MmQyMzRiNzA="
base64.b64decode(code)
# b'admin:202cb962ac59075b964b07152d234b70'

这篇关于如何在python3中解码base64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆