Python error messages, explained
Each page takes one Python error message and shows the code that raises it, what it means and how to fix it. Every example was run on CPython 3.9.6, 3.10.22, 3.11.17, 3.12.15, 3.13.17, 3.14.9 and 3.15.1, and each page shows how every one of those versions words the message.
What is new in Python error messages
New error messages in Python 3.15What changed in Python error messages in 3.15: suggestions through inner attributes and Python names for JavaScript and Java methods. Run on 3.14 and 3.15.New error messages in Python 3.14What changed in Python error messages in 3.14: keyword typo hints, elif after else, string and prefix hints, unhashable keys, async with. Run on 3.13 and 3.14.New error messages in Python 3.13What changed in Python error messages in 3.13: colour tracebacks, a warning when your file shadows a module, keyword argument hints. Run on 3.12 and 3.13.
Python error messages, by exception
- TypeError
- AttributeError
- ValueError
- SyntaxError
- IndentationError
- TabError
- NameError
- UnboundLocalError
- ModuleNotFoundError
- ImportError
- IndexError
- KeyError
- RecursionError
- pip
- Before Python starts
TypeError
TypeError: can only concatenate str (not "int") to strThe Python error 'can only concatenate str (not "int") to str' means + joined text and a number. Python never converts the number for you. Three ways to fix it.TypeError: missing 1 required positional argumentThe Python error "missing 1 required positional argument" names the parameter that got no value. When it says 'self', the class was never instantiated. The fix.TypeError: 'NoneType' object is not subscriptableThe Python error "'NoneType' object is not subscriptable" means you used [ ] on a value that is None. Where the None comes from, and the fix.TypeError: 'str' object is not callableThe Python error "'str' object is not callable" usually means a variable called str, input or a method name now holds a string. How to find it, and the fix.TypeError: takes 1 positional argument but 2 were givenThe Python error "takes 1 positional argument but 2 were given" on a method almost always means a missing self. Why Python counts one more, and the fix.TypeError: unhashable type: 'list'The Python error "unhashable type: 'list'" means a list was used as a dict key or set member. Python 3.14 words it as "cannot use 'list' as a dict key". The fix.
AttributeError
AttributeError: 'list' object has no attributeThe Python error "'list' object has no attribute" means a method from another language, like push, or a str method on a list. Python 3.15 names the fix.AttributeError: module has no attributeThe Python error "module 'random' has no attribute 'randint'" usually means your own file is named like the module. Python 3.13 says so outright. The fix.AttributeError: 'NoneType' object has no attributeThe Python error "'NoneType' object has no attribute" means a call or lookup gave you None instead of an object. The usual sources, and the fix.
ValueError
ValueError: invalid literal for int() with base 10The Python error "invalid literal for int() with base 10" means int() got text that is not a whole number, such as '12.50', '' or '1,000'. The fix for each case.ValueError: not enough values to unpackThe Python error "not enough values to unpack (expected 2, got 1)": the right side has fewer items than names on the left, usually a split with no separator.ValueError: too many values to unpackThe Python error "too many values to unpack (expected 2)" means the right side has more items than names on the left. The usual case is a loop over a dict.
SyntaxError
SyntaxError: expected ':'The Python error "expected ':'" means a line that opens a block, such as if, for, def or class, does not end with a colon. Where the colon goes, and the fix.SyntaxError: invalid syntaxThe Python error "SyntaxError: invalid syntax" marks where the parser gave up, often just after the mistake. The usual causes, and what newer Pythons say.SyntaxError: '(' was never closedThe Python error "'(' was never closed" points at a bracket with no closing partner. How to find it, and the related "does not match opening parenthesis" error.
IndentationError
IndentationError: expected an indented blockThe Python error "expected an indented block" means a line ending in a colon has no indented body under it. How to read the message, and the fix.IndentationError: unindent does not match any outer indentation levelThe Python error "unindent does not match any outer indentation level" means a line was moved back to a column no block started at. How to find it, and the fix.