10 errors documented

Python Error Reference

Common Python errors explained with causes, fixes, and code examples

Python Errors

Standard Python exception classes you'll encounter in any Python application.

ImportError

ImportError is raised when Python cannot find or load a module specified in an import statement. Its subclass ModuleNotFoundError (Python 3.6+) is raised when the module itself doesn't exist.

AttributeError

AttributeError is raised when you try to access an attribute or method that doesn't exist on an object. This includes calling methods on the wrong type or accessing misspelled attribute names.

KeyError

KeyError is raised when you try to access a dictionary key that doesn't exist. This happens with bracket notation (dict[key]) but not with the .get() method.

ValueError

ValueError is raised when a function receives an argument of the right type but an inappropriate value. For example, int('abc') raises ValueError because 'abc' is a string (correct type) but not a valid integer representation.

TypeError

TypeError is raised when an operation or function is applied to an object of inappropriate type. This is different from ValueError, which deals with the right type but wrong value.

IndentationError

IndentationError is a subclass of SyntaxError raised when Python encounters incorrect indentation. Since Python uses indentation to define code blocks, inconsistent or missing indentation prevents the code from being parsed.

NameError

NameError is raised when Python encounters a name (variable, function, class) that hasn't been defined in the current scope. This includes typos, variables used before assignment, and missing imports.

IndexError

IndexError is raised when you try to access a list, tuple, or other sequence using an index that is out of range. The index must be an integer within the bounds of the sequence.

FileNotFoundError

FileNotFoundError is raised when trying to open or access a file or directory that doesn't exist. It's a subclass of OSError and has errno set to ENOENT.

RecursionError

RecursionError is raised when the maximum recursion depth is exceeded (default 1000). It's a subclass of RuntimeError and typically indicates infinite recursion or an algorithm that recurses too deeply.

Track all these errors automatically

Checkend captures Python errors with full context—tracebacks, request data, and more. Self-hosted, so your error data stays on your servers.