lundi 4 juillet 2016

Incorrect Padding error while decoding base64 encoding


I have tried to decode a PDF I stored as BLOB and save it into a file with .pdf extension. results[0][1] has the BLOB data extracted from database query.

         blob_val=results[0][1]
         if len(blob_val) % 4 != 0:
            while len(blob_val) % 4 != 0:
              blob_val = blob_val + b"="
            decod_text = base64.b64decode(blob_val)
         else:
            decod_text = base64.b64decode(blob_val)

Eventhough i have added = at the end to correct padding errors, it is still showing incorrect padding error. why does it still shows this error even when we corrected it by "="?


Aucun commentaire:

Enregistrer un commentaire