pythonbase64

Decoding base64 encoded strings


I have a question about decoding base64 encoded urls:

import base64
url64="aHR0cDovLzR1ZnJlZS50ay9tZWRpYTcyMzY0Ni9mdWVuZi8wMzYubXAzA"
finalUrl=base64.b64decode(url64)

Won't work! TypeError: Incorrect padding

I've also tried to add the needed padding:

import base64
url64="aHR0cDovLzR1ZnJlZS50ay9tZWRpYTcyMzY0Ni9mdWVuZi8wMzYubXAzA"
finalUrl=base64.b64decode(url64 + '=' * (4 - len(url64) % 4))

but im still getting

TypeError: Incorrect padding

Any solution for this?


Solution

  • It would appear that the final A is superfluous:

    In [4]: base64.b64decode('aHR0cDovLzR1ZnJlZS50ay9tZWRpYTcyMzY0Ni9mdWVuZi8wMzYubXAz')
    Out[4]: 'http://4ufree.tk/media723646/fuenf/036.mp3'