Built-in Exceptions

UnicodeEncodeError — exception class

Text cannot be represented by the requested encoding under the chosen error policy. Inspect encoding, object and the failed character span. Use the correct encoding or an explicitly justified error policy rather than silently dropping data. Catch UnicodeEncodeError when this category is the recovery boundary; do not rely on the exact human-readable message.

Formal Syntax & Structure

python syntaxpython
UnicodeEncodeError

Return Value

type

The class object UnicodeEncodeError; this reference documents the class identity, not a universal constructor signature.

Working Example

Example Snippetpython
try:    "é".encode("ascii")except UnicodeEncodeError as error:    print(type(error).__name__)
Python Reference