Python Glossary Русский

all Python 3base64function

base64.b32decode()

Base32 and Base16

Decodes Base32 into bytes. By default it requires capital letters; casefold and map01 relax the check for hand-typed input.

Syntax

base64.b32decode(s, casefold=False, map01=None)

Although Base32 is meant to be case-insensitive, lowercase letters raise binascii.Error unless casefold=True, a common reason a secret typed by a user is rejected. map01 lets the digit 0 count as the letter O and 1 as I or L. Spaces used to group a secret must be removed by hand.

Examples

import base64
import binascii
try:
    base64.b32decode('nbuq====')
except binascii.Error as e:
    print(type(e).__name__)  # → Error
print(base64.b32decode('nbuq====', casefold=True))  # → b'hi'
import base64
secret = 'NBUQ ===='  # пробелы для удобства чтения
print(base64.b32decode(secret.replace(' ', '')))  # → b'hi'

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy