[issue10807] `b'dGVzdA==\n'.decode('base64')` raise exception

STINNER Victor report at bugs.python.org
Sun Jan 2 20:00:01 CET 2011


STINNER Victor <victor.stinner at haypocalc.com> added the comment:

base64, bz2, hex, quopri, rot13, uu and zlib codecs (reintroduced recently by r86934, issue #7475) cannot be used by str.encode/bytes.decode, but with .transform() and .untransform() methods of bytes and str objects. But these methods were removed by r87176.

The last solution to use base64 codec is:

>>> import codecs
>>> codecs.lookup('base64').decode(b'YWJj\n')[0]
b'abc'
>>> codecs.lookup('base64').encode(b'YWJj\n')[0]
b'abc'

Or simply use directly the base64 module:

>>> import base64
>>> base64.decodebytes(b'YWJj\n')
b'abc'
>>> base64.encodebytes(b'abc')
b'YWJj\n'

base64, bz2, hex, quopri, rot13, uu and zlib codecs should be removed from encodings.aliases (because they introduced a confusion for Python 2 users), or removed completly (because it's easier to use directly the related module, eg. base64 or zlib).

----------
nosy: +haypo

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10807>
_______________________________________


More information about the Python-bugs-list mailing list