45 errors you will actually meet, each with what Python is complaining about, the code that causes it, and the fix. Every example runs in the browser — break it, read the traceback, repair it, run it again.
Holding the exact message? Find its family below. Only know when it broke? Browse by when it happens.
TypeError: 'NoneType' object is not iterableYou tried to loop over (or unpack, or *-spread) something that turned out to be None.
TypeError: 'NoneType' object is not subscriptableYou used square brackets — x[0], x["name"], x[1:3] — on a value that is None.
TypeError: 'X' object is not callableYou put () after something that isn't a function.
TypeError: 'int' object is not subscriptableYou used square brackets — x[0], x["key"], x[1:3] — on a value that turned out to be an integer.
TypeError: 'str' object does not support item assignmentYou tried to mutate a string in place with s[0] = "X".
TypeError: list indices must be integers or slices, not strYou indexed a list with a string, like users["name"].
TypeError: unhashable type: 'list'You tried to use a list as a dictionary key or as a member of a set.
TypeError: unsupported operand type(s) for +: 'int' and 'str'Python refuses to glue a number and a string together with +.
AttributeError: 'NoneType' object has no attribute 'X'You called a method or accessed an attribute on None.
AttributeError: 'list' object has no attribute 'X'You called a method on a list that lists simply don't have.
AttributeError: module 'X' has no attribute 'Y'You imported a module successfully, but the function or class you tried to use isn't inside it.
RuntimeError: Event loop is closedSomething asked the asyncio event loop to do work after the loop had already shut down.
RuntimeError: This event loop is already runningYou called asyncio.run() — or loop.run_until_complete() — from inside code that an event loop was already running.
RuntimeError: dictionary changed size during iterationYou are iterating over a dict (or a set, which raises the same kind of error) and you added or removed a key during the loop.
ValueError: invalid literal for int() with base 10You passed int() a string that isn't a valid base-10 integer.
ValueError: not enough values to unpackYou asked Python to unpack an iterable into more variables than it actually contained.
ValueError: too many values to unpackYou tried to unpack an iterable into a fixed number of variables, but the iterable had more items than variables.
ImportError: cannot import name 'X' from 'Y'Python found and successfully imported module Y, but when it tried to bind the name X from inside Y, that name was not there.
ImportError: cannot import name 'X' from partially initialized module (most likely due to a circular import)Two modules import each other.
IndentationError: expected an indented blockPython opened a block with : (after if, for, def, class, while, try, else, with, etc.) but found no indented lines underneath it.
IndentationError: unindent does not matchPython's indentation is part of its grammar.
IndexError: list index out of rangeYou asked Python for an item at a position that doesn't exist in the list.
IndexError: string index out of rangeYou indexed into a string at a position that doesn't exist.
OSError: [Errno 24] Too many open filesYour process hit the operating system's limit on open file descriptors.
OSError: [Errno 98] Address already in useYou tried to bind a server to a port that something else already holds.
'python' is not recognized as an internal or external command: 'python' is not recognized as an internal or external commandWindows looked for a program called python in every folder listed in your PATH environment variable and didn't find one.
ConnectionRefusedError: [Errno 111] Connection refusedYour code reached the machine, and the machine said no.
FileNotFoundError: [Errno 2] No such file or directoryThe OS tried to open the path you gave it and there is nothing at that path.
KeyError: 'X'A KeyError is raised when you try to access a key in a dictionary (or a dict-like object) that does not exist.
MemoryError: MemoryErrorPython asked the operating system for memory and was refused.
ModuleNotFoundError: No module named 'X'The import machinery walked every entry in sys.path — your script's directory, the standard library, site-packages — and could not find a package or module called X.
NameError: name 'X' is not definedPython tried to look up the name X and couldn't find it in any scope — not locally, not globally, not in built-ins.
PermissionError: [Errno 13] Permission deniedThe path exists, but the OS refused the operation because your process does not have permission for it.
RecursionError: maximum recursion depth exceededEvery function call adds a frame to Python's call stack.
SSLCertVerificationError: certificate verify failed: unable to get local issuer certificateThe connection was made and the server presented a certificate, but Python could not build a chain of trust from that certificate up to a root authority it recognises.
SyntaxError: invalid syntaxPython could not parse your source code.
TabError: inconsistent use of tabs and spacesPython uses indentation to delimit blocks.
TimeoutError / requests.exceptions.ReadTimeout: TimeoutError / requests.exceptions.ReadTimeoutYou asked, and nothing came back within the time you allowed.
UnboundLocalError: local variable referenced before assignmentPython decides at compile time, not run time, which names inside a function are local.
UnicodeDecodeError: 'utf-8' codec can't decode byteYou opened a file (or decoded a bytes object) telling Python it was UTF-8, but the bytes don't form valid UTF-8.
UnicodeEncodeError: 'ascii' codec can't encode characterYou are writing text out — to a file, a terminal, a socket — and the encoding in use has no way to represent one of the characters.
ZeroDivisionError: division by zeroYou tried to divide a number by zero.
error: externally-managed-environmentpip refused to install into the Python that came with your operating system.
json.JSONDecodeError: Expecting valuejson.loads or json.load could not parse the input as JSON.
socket.gaierror: [Errno -2] Name or service not knownDNS could not turn the hostname into an IP address.
Python will not even start the file. Nothing has run yet, so nothing is half-done.
'python' is not recognized as an internal or external commandIndentationError: expected an indented blockIndentationError: unindent does not matchSyntaxError: invalid syntaxTabError: inconsistent use of tabs and spaces
The file parses, but something it needs is missing, misplaced, or importing you back.
ImportError: cannot import name 'X' from 'Y'ImportError: cannot import name 'X' from partially initialized module (most likely due to a circular import)ModuleNotFoundError: No module named 'X'error: externally-managed-environment
The program is running and meets a value it cannot work with. The most common kind by far.
AttributeError: 'NoneType' object has no attribute 'X'AttributeError: 'list' object has no attribute 'X'AttributeError: module 'X' has no attribute 'Y'IndexError: list index out of rangeIndexError: string index out of rangeKeyError: 'X'NameError: name 'X' is not definedRecursionError: maximum recursion depth exceededRuntimeError: dictionary changed size during iterationTypeError: 'NoneType' object is not iterableTypeError: 'NoneType' object is not subscriptableTypeError: 'X' object is not callableTypeError: 'int' object is not subscriptableTypeError: 'str' object does not support item assignmentTypeError: list indices must be integers or slices, not strTypeError: unhashable type: 'list'TypeError: unsupported operand type(s) for +: 'int' and 'str'UnboundLocalError: local variable referenced before assignmentValueError: invalid literal for int() with base 10ValueError: not enough values to unpackValueError: too many values to unpackZeroDivisionError: division by zero
Files, encodings, permissions. The logic is fine; the data or the disk is not what you assumed.
FileNotFoundError: [Errno 2] No such file or directoryPermissionError: [Errno 13] Permission deniedUnicodeDecodeError: 'utf-8' codec can't decode byteUnicodeEncodeError: 'ascii' codec can't encode characterjson.JSONDecodeError: Expecting value
Nothing wrong with the code on your laptop. These arrive at 2am — the network, the limits, and the loop.
ConnectionRefusedError: [Errno 111] Connection refusedMemoryErrorOSError: [Errno 24] Too many open filesOSError: [Errno 98] Address already in useRuntimeError: Event loop is closedRuntimeError: This event loop is already runningSSLCertVerificationError: certificate verify failed: unable to get local issuer certificateTimeoutError / requests.exceptions.ReadTimeoutsocket.gaierror: [Errno -2] Name or service not known
An error not listed here usually means the traceback is pointing somewhere other than where the mistake is. Errors & Exceptions covers how to read one properly, and Exceptions: Patterns Beyond the Basics covers raising your own.