Python b64decode incorrect padding

I am sending the file in small UDP packets. (python 3) On the server, I divide the file into small pieces and do

packets.append(b64encode(smallPart))

on the other hand I'm doing exactly the opposite

packets.append(b64decode(peice))    

However, I keep getting (in all but the package) an exception throw exception

Is there a standard size for b64decode that I am missing?

+3
source share
4 answers

Your description of what you are doing sounds normal. The choice of input size only affects efficiency. Byte bytes are minimized if the length of each input part (except, of course, the last) is a multiple of 3.

, . : . . .

: b64encode , , , , , b''.join(pieces) b64decode, ?

: , UDP- ; base64?

+4

64 3 4 . 4 3 . 3 , - '=', 4 . b64decode 4 , .

- , 4 .

+5

base64 4.

Base64 3 4, , , 3, = , 3 (. http://en.wikipedia.org/wiki/Base64#Padding).

As the alignment is aligned, the number of characters is =also equal to the number of characters shaded by 4 in coded form.

+2
source

I tried to decode a base64 encoded string protected by a url. Just replacing the "." with "=" helped.

s = s.replace('.', '=')
# then base64decode
+1
source

All Articles