Message 75911 - Python tracker (original) (raw)

See below. unicode string causes exception. Explicitly converting it to a regular string addresses the issue. I only noticed this because my input string changed to unicode after updating python to 2.6 and django to 1.0.

import base64

a=u'aHR0cDovL3NvdXJjZWZvcmdlLm5ldC90cmFja2VyMi8_ZnVuYz1kZXRhaWwmYWlkPTIyNTg5MzUmZ3JvdXBfaWQ9MTI2OTQmYXRpZD0xMTI2OTQ='

b=base64.urlsafe_b64decode(a) Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.6/base64.py", line 112, in urlsafe_b64decode return b64decode(s, '-_') File "/usr/local/lib/python2.6/base64.py", line 71, in b64decode s = _translate(s, {altchars[0]: '+', altchars[1]: '/'}) File "/usr/local/lib/python2.6/base64.py", line 36, in _translate return s.translate(''.join(translation)) TypeError: character mapping must return integer, None or unicode b=base64.urlsafe_b64decode(str(a)) b 'http://sourceforge.net/tracker2/?func=detail&aid=2258935&group_id=12694&atid=112694'