all Python 3binasciiexception
binascii.Error
exceptions
The binascii exception for bad data: odd-length hex, bad base64 padding, a uu line that is too long. A subclass of ValueError.
Syntax
except binascii.Error:
base64.b64decode and the other base64 functions raise it too, so catch binascii.Error or ValueError rather than a non-existent base64.Error. Not every bad input gives this exact type: a str with non-ASCII characters is rejected with a plain ValueError before parsing, and a wrong argument type raises TypeError.
Examples
import binascii
print(issubclass(binascii.Error, ValueError)) # → True
try:
binascii.a2b_base64('abc')
except binascii.Error as e:
print(e) # → Incorrect padding
import binascii
try:
binascii.a2b_hex('жж')
except binascii.Error:
print('binascii.Error')
except ValueError:
print('plain ValueError') # → plain ValueError
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy