Python Glossary Русский

Python 3.1+base64function

base64.decodebytes()

legacy interface

Decodes multi-line Base64 (as produced by encodebytes or found in e-mail) into bytes. It accepts bytes-like objects only.

Syntax

base64.decodebytes(s)

Unlike b64decode, it does not accept str: decodebytes('aGk=') raises TypeError. Newlines and other junk are skipped silently, and there is no strict mode at all. In practice b64decode does the same more flexibly, so decodebytes mostly pairs with encodebytes. It replaced the removed decodestring.

Examples

import base64
print(base64.decodebytes(b'eHh4\neHh4\n'))  # → b'xxxxxx'
try:
    base64.decodebytes('aGk=')
except TypeError as e:
    print(type(e).__name__)  # → TypeError

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy