Python Glossary Русский

all Python 3until 3.9Removed from the standard libraryfunction

base64.encodestring()

removed

Old name of base64.encodebytes(): Base64 with a newline every 76 characters. Removed in Python 3.9; use encodebytes() instead.

Syntax

base64.encodestring(data)  # до 3.9

The function encodes bytes as MIME-style Base64: lines of 76 characters with a trailing newline. The name with "string" came from Python 2; 3.1 added the precise encodebytes(), and 3.9 removed the alias. How to rewrite: base64.encodestring(data) becomes base64.encodebytes(data), byte for byte the same result. If you do not want newlines (URLs, JSON, headers), use base64.b64encode(data).

Examples

# Python 3.9+
import base64
try:
    base64.encodestring(b'hi')
except AttributeError as e:
    print(type(e).__name__)  # → AttributeError
# Python 3.9+
import base64
print(base64.encodebytes(b'hi'))  # → b'aGk=\n'
print(base64.b64encode(b'hi'))  # → b'aGk='
import base64
print(base64.encodestring(b'hi'))  # → b'aGk=\n'

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy