python b64decode不正确的填充 [英] python b64decode incorrect padding

查看:146
本文介绍了python b64decode不正确的填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过小型UDP数据包发送文件. (python 3) 在服务器上,我将文件分成小块,然后进行

I'm sending a file over small UDP packets. (python 3) On the server I divide the file into small pieces and do

packets.append(b64encode(smallPart))

相反,我恰恰相反

packets.append(b64decode(peice))    

但是,我不断收到(除了数据包以外的所有信息)不正确的填充异常

However, I keep getting (in all but on packet) Incorrect Padding exception

我缺少标准的b64decode大小吗?

Is there a standard size for b64decode that I'm missing?

推荐答案

您对自己正在做的事情的描述听起来不错.输入件尺寸的选择仅影响效率.如果每个输入片段的长度(最后一个除外)的长度是3的倍数,则填充字节将最小化.

Your description of what you are doing sounds OK. Choice of the input piece size affects only the efficiency. Padding bytes are minimised if the length of each input piece (except of course the last) is a multiple of 3.

您需要向我们展示您的服务器代码和客户端代码.或者:在服务器上,记录输入和发送的片段.在客户端上,记录收到的邮件.比较.

You need to show us both your server code and your client code. Alternatively: on the server, log the input and the pieces transmitted. On the client, log the pieces received. Compare.

好奇心:为什么不只是对整个字符串进行b64编码,按自己的意愿分割编码结果,传输片段,在客户端使用b''.join(pieces)重新组装片段,然后b64对其进行解码?

Curiosity: Why don't you just b64encode the whole string, split the encoded result however you like, transmit the pieces, at the client reassemble the pieces using b''.join(pieces) and b64decode that?

进一步的好奇心:我认为UDP数据包的内容可以是任何旧的二进制字节;您为什么要进行base64编码?

Further curiosity: I thought the contents of a UDP packet could be any old binary bunch of bytes; why are you doing base64 encoding at all?

这篇关于python b64decode不正确的填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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