all Python 3binasciifunction
binascii.a2b_qp()
uuencode and quoted-printable
Decodes quoted-printable to bytes: =XX turns into bytes, and soft line breaks '=\n' are removed. The result is bytes; get text with .decode().
Syntax
binascii.a2b_qp(data, header=False)
A common mistake is expecting str: after a2b_qp you still need .decode() with the charset from the email header. A soft break, '=' at the end of a line, joins lines, so the output has fewer lines than the input. Underscores turn into spaces only with header=True; in a message body '_' stays '_'.
Examples
import binascii
raw = binascii.a2b_qp(b'=D0=9F=D1=80=\n=D0=B8')
print(raw) # → b'\xd0\x9f\xd1\x80\xd0\xb8'
print(raw.decode('utf-8')) # → При
print(binascii.a2b_qp(b'a_b'), binascii.a2b_qp(b'a_b', header=True)) # → b'a_b' b'a b'
See also
Open in the full glossarydocs.python.orgReport an inaccuracy