all Python 3until 3.9Removed from the standard libraryfunction
base64.decodestring()
removed
Old name of base64.decodebytes(): decodes MIME-style Base64 back to bytes. Removed in Python 3.9; use decodebytes() instead.
Syntax
base64.decodestring(data) # до 3.9
The counterpart of encodestring(): takes Base64 split into lines and returns the original bytes. Since Python 3.1 it has the precise name decodebytes(); 3.9 removed the old one. How to rewrite: base64.decodestring(data) becomes base64.decodebytes(data). For Base64 without newlines base64.b64decode(data) works too. Both expect bytes; turn a str into bytes first with .encode('ascii').
Examples
# Python 3.9+
import base64
try:
base64.decodestring(b'aGk=\n')
except AttributeError as e:
print(type(e).__name__) # → AttributeError
# Python 3.9+
import base64
print(base64.decodebytes(b'aGk=\n')) # → b'hi'
print(base64.b64decode('aGk='.encode('ascii'))) # → b'hi'
import base64
print(base64.decodestring(b'aGk=\n')) # → b'hi'
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy