When decoding base64-encoded data in Python, an "Incorrect padding" error is encountered. Is there a way to ignore this error and proceed with the decoding process?
To bypass the "Incorrect padding" error, padding characters should be added to the encoded bytes before decoding it.
There are several ways to achieve this:
For example:
<code class="python">import base64 encoded_bytes = "abc" decoded_bytes = base64.b64decode(encoded_bytes + "==")</code>
Note that adding maximum padding (two characters) is sufficient, even if the original encoded string contains some padding.
Additionally, if the validate keyword argument in the base64.b64decode() function is set to False (the default), non-alphabet characters in the encoded string will be ignored, allowing for the addition of padding characters without encountering errors.
Das obige ist der detaillierte Inhalt vonWie kann ich „Falsche Auffüllung'-Fehler während der Python Base64-Dekodierung umgehen?. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!