python
encoding_error
ai_generated
true
LookupError: unknown encoding: utf8
ID: python/lookuperror-unknown-encoding
95%Fix Rate
95%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 311 | active | — | — | — |
Root Cause
Misspelled encoding name. utf8 → utf-8, ascii → ascii, latin1 → latin-1.
genericWorkarounds
-
98% success Use the correct encoding name: 'utf-8' (with hyphen), not 'utf8'
open('file.txt', encoding='utf-8') # not 'utf8' or 'UTF_8'Sources: https://docs.python.org/3/library/codecs.html#standard-encodings
-
90% success Check Python's list of standard encodings for the correct name
Check Python's list of standard encodings for the correct name
Sources: https://docs.python.org/3/library/codecs.html#standard-encodings
Dead Ends
Common approaches that don't work:
-
Install a codec package
80% fail
Standard encodings are built into Python — no package needed
-
Set PYTHONIOENCODING environment variable
70% fail
Doesn't fix the encoding name in your code
Error Chain
Frequently confused with: