Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Decoding base64 encoded strings

Tags:

python

base64

I'm new to python and 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

Would be great if someone knows a solution for this.

like image 626
pythonNewbie Avatar asked Nov 25 '12 20:11

pythonNewbie


1 Answers

It would appear that the final A is superfluous:

In [4]: base64.b64decode('aHR0cDovLzR1ZnJlZS50ay9tZWRpYTcyMzY0Ni9mdWVuZi8wMzYubXAz')
Out[4]: 'http://4ufree.tk/media723646/fuenf/036.mp3'
like image 82
NPE Avatar answered Oct 08 '22 07:10

NPE