Python base64.b32decode Bug


I’m suffering from a python2.4 b32decode bug where a valid base32-encoded string fails to decode properly.

from base64 import b32encode, b32decode
binary = '\x1b\xbf@\x1e\x0e\x01\x10 \x83\xf6\x000H5\xb2\xee’
encoded = b32encode(binary)
decoded = b32decode(encoded)

This bug does not present itself in python 2.4.4 on my Intel Mac (OS X 10.5.1). Please help!

I forgot to include the bug itself. See for yourself:

$ python2.4
Python 2.4.1 (#2, Oct 18 2006, 20:58:01)
[GCC 3.3.5 (Debian 1:3.3.5-13)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.


Traceback (most recent call last):
File “”, line 1, in ?
File “/usr/lib/python2.4/”, line 224, in b32decode
TypeError: Odd-length string


Apparently this was a bug in Python 2.4.1, that was fixed in later versions. (I looked at 2.5.1, and the b32decode is slightly different.) You could grab a fixed version of b32decode from OS X and use it instead.