Re: base64 Incorrect Padding
- From: MRAB <python@xxxxxxxxxxxxxxxxxxx>
- Date: Fri, 31 Jul 2009 22:17:30 +0100
Max Erickson wrote:
MRAB <python@xxxxxxxxxxxxxxxxxxx> wrote:Oops, correct! :-)
Brandon Fredericks wrote:I did a search within this group, but couldn't find anyBase-64 encodes 3 bytes (echo in the range 0-255) to 4 bytes
information on this.
I am sending base64 encoded data as the content over http using
urllib2 urlopen. When I receive the data and attempt to decode
it, I get an "Incorrect Padding" error. Is there a simple way to
fix this? A better way to send and receive the data possibly
(using base64 of course)?
(each in a more restricted range). The length of the output is
_always_ a multiple of 4 (ignoring whitespace); the method adds
extra padding bytes (ASCII '=') to ensure that this is the case
if the length of the input isn't a multiple of 3.
So, if decoding raises an "Incorrect Padding" error then strip
out any whitespace and append extra ASCII '=' to make its length
a multiple of 3, then try decoding again. (Or you could just
repeatedly add one pad character and retry, up to 3 times.)
The length of the encoded string should be a multiple of 4 (as you state in the second sentence of your post), not a multiple of 3.
.
- References:
- base64 Incorrect Padding
- From: Brandon Fredericks
- base64 Incorrect Padding
- Prev by Date: Re: Python docs disappointing
- Previous by thread: Re: base64 Incorrect Padding
- Next by thread: Newbie Question regarding __init__()
- Index(es):
Relevant Pages
|