Skip to content

Instantly share code, notes, and snippets.

@x
Created April 1, 2021 21:20
Show Gist options
  • Save x/f201197f8c1a6255aff822f670371fe1 to your computer and use it in GitHub Desktop.
Save x/f201197f8c1a6255aff822f670371fe1 to your computer and use it in GitHub Desktop.
Unicode decode with abstract
try:
message.decode('utf-8')
except UnicodeDecodeError as err:
abstract = message[max(err.start - 10, 0):min(err.end + 10, len(message))].decode(encoding, 'backslashreplace')
logging.error(f"Error decoding as UTF-8: {uuid} Problem Area: '{abstract}' Error: {err}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment