LookupError: Unknown Encoding

LookupError: unknown encoding: utf8mb4

Quick Answer

The encoding name is not recognized by Python. Check against Python's standard encoding names. MySQL utf8mb4 is Python utf-8.

Why This Happens

Python uses specific encoding names that may differ from other systems. MySQL's utf8mb4 is Python's utf-8. Check the Python docs for supported names.

The Problem

data = b'Hello'
text = data.decode('utf8mb4')

The Fix

data = b'Hello'
text = data.decode('utf-8')

Step-by-Step Fix

  1. 1

    Use standard names

    Use 'utf-8', 'ascii', 'latin-1', 'cp1252'.

  2. 2

    Map from other systems

    Convert encoding names from databases to Python equivalents.

  3. 3

    Check available encodings

    See Python's codecs module documentation.

Got the actual stack trace?

Paste it into our free AI explainer to get the cause and the fix for your specific case — no signup, nothing to install.

Explain my error

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free