[New-bugs-announce] [issue4329] base64 does not properly handle unicode strings
Michael Becker
report at bugs.python.org
Sat Nov 15 12:11:25 CET 2008
New submission from Michael Becker <spammb at gmail.com>:
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 "<stdin>", line 1, in <module>
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'
----------
components: Unicode
messages: 75911
nosy: mbecker
severity: normal
status: open
title: base64 does not properly handle unicode strings
versions: Python 2.6
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4329>
_______________________________________
More information about the New-bugs-announce
mailing list