60 errors you are likely to meet, each with what the error message means, the code that causes it, and the fix. Every example runs in the browser: break it, read the traceback, fix it, and run it again.
Holding the exact message? Paste it and we'll find the page, or find its family below. Only know when it broke? Browse by when it happens.
Paste the whole traceback, or just its last line. We'll find the page that fixes it, or show you how to read it if we don't have one yet. It's read here in your browser, and your error never leaves this tab unless you choose to send it to us.
TypeError: 'NoneType' object is not iterableYou tried to loop over a value that is None, or passed it to a function that loops over it, like list(), sorted() or sum().
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: 'float' object cannot be interpreted as an integerYou gave a float (a number like 3.0 or 2.5) to something that only works with whole numbers, and Python refused to round it for you.
TypeError: 'int' object is not subscriptableYou used square brackets (x[0], x["key"], x[1:3]) on a value that is an integer.
TypeError: 'str' object does not support item assignmentYou tried to mutate a string in place with s[0] = "X".
TypeError: Object of type datetime is not JSON serializablejson.dumps (or json.dump) found a value it doesn't know how to write as JSON.
TypeError: got an unexpected keyword argumentYou called a function with name=value, and the function has no parameter called name.
TypeError: list indices must be integers or slices, not strYou indexed a list with a string, like users["name"].
TypeError: missing 1 required positional argumentYou called a function with fewer arguments than its def line asks for.
TypeError: object of type 'int' has no len()len() asks an object how many items it holds.
TypeError: takes 1 positional argument but 2 were givenA function received more positional arguments than its def line accepts.
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 +: 'NoneType' and 'int'You tried to add a number to None.
TypeError: unsupported operand type(s) for +: 'int' and 'str'Python refuses to join a number and a string with +.
AttributeError: 'DataFrame' object has no attribute 'append'Your code calls df.append(...), and that method no longer exists.
AttributeError: 'NoneType' object has no attribute 'X'You called a method or accessed an attribute on None.
AttributeError: 'dict' object has no attribute 'X'You used dot access (user.name) on a dictionary.
AttributeError: 'list' object has no attribute 'X'You called a method that lists don't have.
AttributeError: 'str' object has no attribute 'X'You asked a string for a method it doesn'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.
ValueError: The truth value of a Series is ambiguousSomething asked a pandas Series for a single True or False, and a Series of many values can't give one.
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 the number of items it contains.
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: attempted relative import with no known parent packageThe file has an import with a leading dot (from .totals import invoice_total), and Python doesn't know which package that dot refers to.
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: unexpected indentA line starts further to the right than Python expected.
IndentationError: unindent does not matchPython's indentation is part of its grammar.
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 code that is already running inside an event loop.
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.
SyntaxError: '(' was never closedYou opened a bracket ((, [ or {) and Python never found the one that closes it.
SyntaxError: invalid syntaxPython could not parse your source code.
SyntaxError: unterminated string literalPython found an opening quote and reached the end of the line without finding the matching closing quote.
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'Python searched every folder 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 in the local scope, not in the global scope, and not in the 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.
TabError: inconsistent use of tabs and spacesPython uses indentation to mark where blocks start and end.
TimeoutError / requests.exceptions.ReadTimeout: TimeoutError / requests.exceptions.ReadTimeoutYou sent a request, and no answer 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 cannot 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: unexpected indentIndentationError: unindent does not matchSyntaxError: '(' was never closedSyntaxError: invalid syntaxSyntaxError: unterminated string literalTabError: inconsistent use of tabs and spaces
The file parses, but something it needs is missing, misplaced, or importing you back.
ImportError: attempted relative import with no known parent packageImportError: 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: 'DataFrame' object has no attribute 'append'AttributeError: 'NoneType' object has no attribute 'X'AttributeError: 'dict' object has no attribute 'X'AttributeError: 'list' object has no attribute 'X'AttributeError: 'str' 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: 'float' object cannot be interpreted as an integerTypeError: 'int' object is not subscriptableTypeError: 'str' object does not support item assignmentTypeError: Object of type datetime is not JSON serializableTypeError: got an unexpected keyword argumentTypeError: list indices must be integers or slices, not strTypeError: missing 1 required positional argumentTypeError: object of type 'int' has no len()TypeError: takes 1 positional argument but 2 were givenTypeError: unhashable type: 'list'TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'TypeError: unsupported operand type(s) for +: 'int' and 'str'UnboundLocalError: local variable referenced before assignmentValueError: The truth value of a Series is ambiguousValueError: 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, but 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
The code works on your laptop, but fails on a server: network errors, system limits and event-loop problems.
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.