python中两个或多个base64字符串的串联 [英] concatenation of two or more base64 strings in python

查看:76
本文介绍了python中两个或多个base64字符串的串联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图将两个编码为base64的字符串连接起来,但它实际上并没有工作,只是在连接中打印第一个字符串:

I'm tring to concatenate two strings encoded to base64 but it doesn't really work, just prints the first string in concatanation:

q = base64.b64encode("StringA")
print q # prints an encoded string
q = q+base64.b64encode("StringB")
print q # prints an encoded string

print base64.b64decode(q) # just prints "StringA"

推荐答案

您正在解码一个由两个base64字符串串联而成的字符串.这是不正确的.您应该这样做-

You are decoding a string that is concatenation of two base64 strings. This is not correct. You should do something like this -

base64.b64decode(base64.b64encode("StringA" + "StringB"))

这篇关于python中两个或多个base64字符串的串联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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