New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
b'dGVzdA==\n'.decode('base64')
raise exception
#55016
Comments
>>> b'dGVzdA==\n'.decode('base64')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "../Lib/encodings/base64_codec.py", line 20, in base64_decode
return (base64.decodebytes(input), len(input))
File "../Lib/base64.py", line 359, in decodebytes
raise TypeError("expected bytes, not %s" % s.__class__.__name__)
TypeError: expected bytes, not memoryview |
base64, bz2, hex, quopri, rot13, uu and zlib codecs (reintroduced recently by r86934, issue bpo-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). |
bpo-10807.patch just disables hex, base64, ... codecs in aliases (so it's still possible to use they through codecs.lookup()). |
That does not look like the right patch... |
Ah yes :-) |
Looks good, please commit. |
Ok, done: r87642 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: