Module (36%)
Section (36%)

The UnicodeError exception – raised when a Unicode-related encoding or decoding error occurs. It is a subclass of ValueError.

The UnicodeError has attributes that describe an encoding or decoding error.

  • encoding – the name of the encoding that raised the error.
  • reason – a string describing the specific codec error.
  • object – the object the codec was attempting to encode or decode.
  • start – the first index of invalid data in the object.
  • end – the index after the last invalid data in the object.

See the output of this snippet to analyze the attributes' values.


Code

try:
b'\x80'.decode("utf-8")
except UnicodeError as e:
print(e)
print(e.encoding)
print(e.reason)
print(e.object)
print(e.start)
print(e.end)
{{ dockerServerErrorMsg }} ×
{{ errorMsg }} ×
{{ successMsg }} ×