List of 127 Python Error Messages & Exceptions – Explained!

Mac laptop on a table

Python, with its simplicity and versatility, has become one of the most popular programming languages in the world. As a developer, you’ve likely encountered various error messages and exceptions that Python throws at you during your coding journey. While these messages may seem daunting at first, understanding and interpreting them is crucial for writing robust and bug-free code.

In this article, we aim to demystify Python error messages and exceptions, providing you with a comprehensive guide that will empower you to navigate through the intricacies of Python’s error handling system. We’ll delve into the depths of the most common error messages, unravel their meanings, and offer insights into the reasons behind their occurrence. Whether you’re a seasoned developer or just starting with Python, this guide will serve as a valuable resource to help you troubleshoot and debug your code effectively.

We’ll cover a wide range of error messages and exceptions, including SyntaxError, TypeError, ValueError, FileNotFoundError, and many more. Each error message will be accompanied by a human-friendly explanation, enabling you to understand the root cause of the error and guiding you towards the appropriate solutions. By the end of this article, you’ll have a solid understanding of Python’s error handling mechanisms, enabling you to write cleaner, more robust code and streamline your debugging process.

So, whether you’re puzzling over a perplexing error message or simply looking to expand your knowledge, join us on this journey as we unravel the mysteries of Python’s error messages and exceptions. Let’s dive in and master the art of handling errors like a pro!

List of Python Error Messages & Exceptions

Error Message Explanation
SyntaxError: invalid syntax This error occurs when there is a syntax mistake in your code, such as a missing or misplaced symbol.
IndentationError: unexpected indent This error indicates that the indentation of your code is incorrect, usually due to mixing spaces and tabs or inconsistent indentation levels.
NameError: name ‘variable’ is not defined This error occurs when you try to use a variable that hasn’t been assigned a value or is out of scope.
TypeError: unsupported operand type(s) This error indicates that you’re performing an operation on incompatible data types or using unsupported operators.
ValueError: invalid literal for int() with base This error is raised when you’re trying to convert a string to an integer, but the string doesn’t represent a valid integer.
ImportError: No module named ‘module_name’ This error occurs when you’re trying to import a module that cannot be found or doesn’t exist in the specified location.
IndexError: list index out of range This error is raised when you’re trying to access a list or sequence using an index that is outside the valid range of indices.
KeyError: ‘key’ not found in dictionary This error occurs when you’re trying to access a dictionary using a key that doesn’t exist in the dictionary.
FileNotFoundError: [Errno 2] No such file or directory: ‘file_path’ This error is raised when you’re trying to access a file that doesn’t exist or the specified file path is incorrect.
ZeroDivisionError: division by zero This error occurs when you’re trying to divide a number by zero, which is mathematically undefined.
AttributeError: ‘class_name’ object has no attribute ‘attribute_name’ This error indicates that you’re trying to access an attribute or method of an object that doesn’t exist in its class definition.
ValueError: could not convert string to float This error occurs when you’re trying to convert a string to a floating-point number, but the string is not a valid float representation.
AssertionError This error is raised when an assert statement fails, indicating that the specified condition is not true.
IOError: [Errno 13] Permission denied This error occurs when you’re trying to perform a file operation, but you don’t have the necessary permissions to access or modify the file.
RecursionError: maximum recursion depth exceeded This error is raised when a recursive function or method exceeds the maximum recursion depth set in Python.
KeyboardInterrupt This error occurs when the user interrupts the program’s execution by pressing Ctrl+C or sending the interrupt signal.
TypeError: ‘type’ object is not iterable This error occurs when you try to iterate over an object that is not iterable, such as an integer or a class.
MemoryError: out of memory This error indicates that the system has run out of memory, usually when trying to allocate memory for a large data structure.
UnicodeError: encoding/decoding error This error occurs when there is an issue with encoding or decoding a Unicode string, such as unsupported characters or incorrect encoding.
ImportError: cannot import name ‘function_name’ This error occurs when you’re trying to import a specific function from a module that doesn’t have that function.
OverflowError: int too large to convert to float This error occurs when you’re trying to convert a very large integer to a float, but the integer is too large to be represented as a float.
AttributeError: ‘module_name’ module has no attribute ‘function_name’ This error indicates that you’re trying to access a function that doesn’t exist in a module.
TabError: inconsistent use of tabs and spaces in indentation This error occurs when you mix tabs and spaces for indentation, leading to inconsistent indentation levels.
OSError: [Errno 2] No such file or directory: ‘file_path’ This error is raised when you’re trying to access a file that doesn’t exist or the specified file path is incorrect.
ImportError: DLL load failed: The specified module could not be found. This error occurs when a required DLL file is missing or cannot be loaded.
KeyboardInterrupt: Execution interrupted by the user This error message is displayed when the user forcefully interrupts the program’s execution.
AttributeError: ‘str’ object has no attribute ‘method’ This error occurs when you’re trying to access a method that doesn’t exist in a string object.
ModuleNotFoundError: No module named ‘module_name’ This error is raised when you’re trying to import a module that cannot be found or doesn’t exist in the specified location.
AssertionError: Expression is not true This error is raised when an assert statement fails, indicating that the specified expression is not true.
TypeError: unsupported operand type(s) for +: ‘int’ and ‘str’ This error occurs when you’re trying to perform addition between incompatible types, such as an integer and a string.
ValueError: math domain error This error is raised when there is an issue with a mathematical operation, such as taking the square root of a negative number.
FileNotFoundError: [Errno 2] No such file or directory: ‘file_path’ This error is raised when you’re trying to access a file that doesn’t exist or the specified file path is incorrect.
IndexError: tuple index out of range This error occurs when you’re trying to access a tuple using an index that is outside the valid range of indices.
KeyError: ‘key’ This error occurs when you’re trying to access a dictionary using a key that doesn’t exist in the dictionary.
SyntaxError: EOL while scanning string literal This error occurs when you have an incomplete or unclosed string literal, usually missing a closing quote.
NameError: global name ‘variable’ is not defined This error occurs when you’re trying to access a global variable that hasn’t been defined in the current scope.
ZeroDivisionError: float division by zero This error occurs when you’re trying to divide a float number by zero, which results in infinity or NaN (Not a Number).
ImportError: cannot import name ‘function_name’ from ‘module_name’ This error occurs when you’re trying to import a specific function from a module, but the function doesn’t exist in that module.
TypeError: ‘NoneType’ object is not iterable This error occurs when you’re trying to iterate over an object that has a value of None, which is not iterable.
FileNotFoundError: [WinError 2] The system cannot find the file specified This error is raised when you’re trying to access a file that doesn’t exist or the specified file path is incorrect.
RecursionError: maximum recursion depth exceeded in comparison This error is raised when a comparison operation inside a recursive function exceeds the maximum recursion depth.
KeyboardInterrupt: Program execution interrupted by the user This error occurs when the user interrupts the program’s execution, typically by pressing Ctrl+C or sending the interrupt signal.
TypeError: ‘dict’ object is not callable This error occurs when you’re trying to call a dictionary as if it were a function.
FileExistsError: [Errno 17] File exists: ‘file_path’ This error is raised when you’re trying to create a file that already exists.
ImportError: cannot import name ‘module_name’ This error occurs when you’re trying to import a module that has a circular import dependency, resulting in an import error.
IndexError: string index out of range This error occurs when you’re trying to access a string using an index that is outside the valid range of indices.
ValueError: invalid literal for int() with base 10: ‘string’ This error is raised when you’re trying to convert a string to an integer, but the string contains invalid characters for an integer.
FileNotFoundError: [Errno 2] No such file or directory: ‘filename’ This error occurs when you’re trying to access a file that doesn’t exist or the specified file path is incorrect.
AttributeError: ‘list’ object has no attribute ‘method’ This error occurs when you’re trying to access a method that doesn’t exist in a list object.
SyntaxError: unexpected EOF while parsing This error occurs when the Python interpreter encounters an unexpected end of file while parsing the code.
NameError: name ‘function_name’ is not defined This error occurs when you’re trying to call a function that hasn’t been defined or is out of scope.
ZeroDivisionError: integer division or modulo by zero This error occurs when you’re trying to perform integer division or modulo operation with zero as the divisor.
ImportError: cannot import module_name This error occurs when you’re trying to import a module that cannot be found or doesn’t exist in the specified location.
TypeError: ‘float’ object is not callable This error occurs when you’re trying to call a float number as if it were a function.
ValueError: could not convert string to float: ‘invalid’ This error occurs when you’re trying to convert a string to a floating-point number, but the string is not a valid float representation.
FileNotFoundError: [Errno 2] No such file or directory: ‘file_path’ This error is raised when you’re trying to access a file that doesn’t exist or the specified file path is incorrect.
OverflowError: integer division result too large for a float This error occurs when the result of an integer division is too large to be represented as a float.
IndentationError: expected an indented block This error occurs when you’re expected to provide an indented block of code after a colon, such as in if statements or function definitions.
KeyError: ‘key’ not found This error occurs when you’re trying to access a dictionary using a key that doesn’t exist in the dictionary.
OSError: [Errno 13] Permission denied: ‘file_path’ This error occurs when you’re trying to perform a file operation, but you don’t have the necessary permissions to access or modify the file.
TypeError: ‘type’ object is not subscriptable This error occurs when you’re trying to perform subscription (indexing/slicing) on a type object, which is not allowed.
TypeError: can only concatenate str (not “int”) to str This error occurs when you’re trying to concatenate a string and an integer without converting the integer to a string first.
ValueError: invalid literal for int() with base 10: ‘123.45’ This error is raised when you’re trying to convert a string to an integer using the int() function, but the string contains decimal points.
ImportError: cannot import module_name: wrong magic number This error occurs when you’re trying to import a compiled Python module that has an incompatible or corrupted file format.
TypeError: ‘NoneType’ object is not subscriptable This error occurs when you’re trying to perform subscription (indexing/slicing) on an object with a value of None.
FileNotFoundError: [Errno 2] No such file or directory: ‘filename’ This error occurs when you’re trying to access a file that doesn’t exist or the specified file path is incorrect.
AttributeError: ‘tuple’ object has no attribute ‘method’ This error occurs when you’re trying to access a method that doesn’t exist in a tuple object.
SyntaxError: invalid character in identifier This error occurs when you use an invalid character in an identifier (variable or function name), such as special symbols or spaces.
NameError: name ‘variable’ is not defined This error occurs when you’re trying to use a variable that hasn’t been assigned a value or is out of scope.
ZeroDivisionError: division by zero This error occurs when you’re trying to divide a number by zero, which is mathematically undefined.
ImportError: cannot import name ‘function_name’ This error occurs when you’re trying to import a specific function from a module that doesn’t have that function.
TypeError: ‘str’ object is not callable This error occurs when you’re trying to call a string as if it were a function.
ValueError: could not convert string to float This error occurs when you’re trying to convert a string to a floating-point number, but the string is not a valid float representation.
AssertionError: ‘expression’ is false This error is raised when an assert statement fails, indicating that the specified expression is not true.
IOError: [Errno 2] No such file or directory: ‘filename’ This error occurs when you’re trying to access a file that doesn’t exist or the specified file path is incorrect.
RecursionError: maximum recursion depth exceeded This error is raised when a recursive function or method exceeds the maximum recursion depth set in Python.
KeyboardInterrupt: Execution interrupted by the user This error occurs when the user interrupts the program’s execution by pressing Ctrl+C or sending the interrupt signal.
TypeError: ‘type’ object is not iterable This error occurs when you try to iterate over an object that is not iterable, such as an integer or a class.
MemoryError: out of memory This error indicates that the system has run out of memory, usually when trying to allocate memory for a large data structure.
UnicodeError: encoding/decoding error This error occurs when there is an issue with encoding or decoding a Unicode string, such as unsupported characters or incorrect encoding.
ImportError: cannot import name ‘function_name’ from ‘module_name’ This error occurs when you’re trying to import a specific function from a module, but the function doesn’t exist in that module.
DeprecationWarning: This is a deprecated feature This warning is issued when you’re using a feature or method that is no longer recommended and may be removed in future versions of Python.
TypeError: ‘list’ object is not callable This error occurs when you’re trying to call a list as if it were a function.
FileNotFoundError: [Errno 2] No such file or directory: ‘file_path’ This error is raised when you’re trying to access a file that doesn’t exist or the specified file path is incorrect.
OverflowError: int too large to convert to float This error occurs when you’re trying to convert a very large integer to a float, but the integer is too large to be represented as a float.
AttributeError: ‘module_name’ module has no attribute ‘function_name’ This error indicates that you’re trying to access a function that doesn’t exist in a module.
TabError: inconsistent use of tabs and spaces in indentation This error occurs when you mix tabs and spaces for indentation, leading to inconsistent indentation levels.
OSError: [Errno 13] Permission denied This error occurs when you’re trying to perform a file operation, but you don’t have the necessary permissions to access or modify the file.
TypeError: ‘NoneType’ object is not iterable This error occurs when you’re trying to iterate over an object that has a value of None, which is not iterable.
MemoryError: out of memory This error indicates that the system has run out of memory, usually when trying to allocate memory for a large data structure.
ImportError: DLL load failed: The specified module could not be found. This error occurs when a required DLL file is missing or cannot be loaded.
KeyboardInterrupt: Execution interrupted by the user This error occurs when the user interrupts the program’s execution by pressing Ctrl+C or sending the interrupt signal.
TypeError: ‘dict’ object is not iterable This error occurs when you’re trying to iterate over a dictionary object directly, which is not allowed.
MemoryError: Unable to allocate array with shape and data type This error occurs when you’re trying to allocate a large array in memory, but there is insufficient memory available.
FileNotFoundError: [Errno 2] No such file or directory: ‘file_path’ This error is raised when you’re trying to access a file that doesn’t exist or the specified file path is incorrect.
AttributeError: ‘str’ object has no attribute ‘method’ This error occurs when you’re trying to access a method that doesn’t exist in a string object.
ImportError: No module named ‘module_name’ This error occurs when you’re trying to import a module that cannot be found or doesn’t exist in the specified location.
IndexError: list index out of range This error is raised when you’re trying to access a list or sequence using an index that is outside the valid range of indices.
KeyError: ‘key’ not found in dictionary This error occurs when you’re trying to access a dictionary using a key that doesn’t exist in the dictionary.
FileNotFoundError: [Errno 2] No such file or directory: ‘file_path’ This error is raised when you’re trying to access a file that doesn’t exist or the specified file path is incorrect.
ZeroDivisionError: division by zero This error occurs when you’re trying to divide a number by zero, which is mathematically undefined.
AttributeError: ‘class_name’ object has no attribute ‘attribute_name’ This error indicates that you’re trying to access an attribute or method of an object that doesn’t exist in its class definition.
ValueError: could not convert string to float This error occurs when you’re trying to convert a string to a floating-point number, but the string is not a valid float representation.
AssertionError This error is raised when an assert statement fails, indicating that the specified condition is not true.
IOError: [Errno 13] Permission denied This error occurs when you’re trying to perform a file operation, but you don’t have the necessary permissions to access or modify the file.
RecursionError: maximum recursion depth exceeded This error is raised when a recursive function or method exceeds the maximum recursion depth set in Python.
KeyboardInterrupt This error occurs when the user interrupts the program’s execution by pressing Ctrl+C or sending the interrupt signal.
TypeError: ‘type’ object is not iterable This error occurs when you try to iterate over an object that is not iterable, such as an integer or a class.
MemoryError: out of memory This error indicates that the system has run out of memory, usually when trying to allocate memory for a large data structure.
UnicodeError: encoding/decoding error This error occurs when there is an issue with encoding or decoding a Unicode string, such as unsupported characters or incorrect encoding.
ImportError: cannot import name ‘function_name’ This error occurs when you’re trying to import a specific function from a module that doesn’t have that function.
DeprecationWarning: This is a deprecated feature This warning is issued when you’re using a feature or method that is no longer recommended and may be removed in future versions of Python.
TypeError: ‘NoneType’ object is not subscriptable This error occurs when you’re trying to perform subscription (indexing/slicing) on an object with a value of None.
FileNotFoundError: [Errno 2] No such file or directory: ‘file_path’ This error is raised when you’re trying to access a file that doesn’t exist or the specified file path is incorrect.
OverflowError: int too large to convert to float This error occurs when you’re trying to convert a very large integer to a float, but the integer is too large to be represented as a float.
AttributeError: ‘module_name’ module has no attribute ‘function_name’ This error indicates that you’re trying to access a function that doesn’t exist in a module.
TabError: inconsistent use of tabs and spaces in indentation This error occurs when you mix tabs and spaces for indentation, leading to inconsistent indentation levels.
OSError: [Errno 13] Permission denied This error occurs when you’re trying to perform a file operation, but you don’t have the necessary permissions to access or modify the file.
TypeError: ‘NoneType’ object is not subscriptable This error occurs when you’re trying to perform subscription (indexing/slicing) on an object with a value of None.
FileNotFoundError: [Errno 2] No such file or directory: ‘file_path’ This error is raised when you’re trying to access a file that doesn’t exist or the specified file path is incorrect.
OverflowError: int too large to convert to float This error occurs when you’re trying to convert a very large integer to a float, but the integer is too large to be represented as a float.
IndentationError: unexpected indent This error indicates that the indentation of your code is incorrect, usually due to mixing spaces and tabs or inconsistent indentation levels.
IndexError: list index out of range This error is raised when you’re trying to access a list or sequence using an index that is outside the valid range of indices.
KeyError: ‘key’ not found in dictionary This error occurs when you’re trying to access a dictionary using a key that doesn’t exist in the dictionary.
SyntaxError: invalid syntax This error occurs when there is a syntax mistake in your code, such as a missing or misplaced symbol.
NameError: name ‘variable’ is not defined This error occurs when you try to use a variable that hasn’t been assigned a value or is out of scope.
TypeError: unsupported operand type(s) This error indicates that you’re performing an operation on incompatible data types or using unsupported operators.
ValueError: invalid literal for int() with base This error is raised when you’re trying to convert a string to an integer, but the string doesn’t represent a valid integer.
ImportError: No module named ‘module_name’ This error occurs when you’re trying to import a module that cannot be found or doesn’t exist in the specified location.
IndexError: list index out of range This error is raised when you’re trying to access a list or sequence using an index that is outside the valid range of indices.
KeyError: ‘key’ not found in dictionary This error occurs when you’re trying to access a dictionary using a key that doesn’t exist in the dictionary.
FileNotFoundError: [Errno 2] No such file or directory: ‘file_path’ This error is raised when you’re trying to access a file that doesn’t exist or the specified file path is incorrect.
ZeroDivisionError: division by zero This error occurs when you’re trying to divide a number by zero, which is mathematically undefined.
AttributeError: ‘class_name’ object has no attribute ‘attribute_name’ This error indicates that you’re trying to access an attribute or method of an object that doesn’t exist in its class definition.
ValueError: could not convert string to float This error occurs when you’re trying to convert a string to a floating-point number, but the string is not a valid float representation.
AssertionError This error is raised when an assert statement fails, indicating that the specified condition is not true.
IOError: [Errno 13] Permission denied This error occurs when you’re trying to perform a file operation, but you don’t have the necessary permissions to access or modify the file.
RecursionError: maximum recursion depth exceeded This error is raised when a recursive function or method exceeds the maximum recursion depth set in Python.
KeyboardInterrupt: Execution interrupted by the user This error occurs when the user interrupts the program’s execution by pressing Ctrl+C or sending the interrupt signal.
TypeError: ‘type’ object is not iterable This error occurs when you try to iterate over an object that is not iterable, such as an integer or a class.
MemoryError: out of memory This error indicates that the system has run out of memory, usually when trying to allocate memory for a large data structure.
UnicodeError: encoding/decoding error This error occurs when there is an issue with encoding or decoding a Unicode string, such as unsupported characters or incorrect encoding.
ImportError: cannot import name ‘function_name’ from ‘module_name’ This error occurs when you’re trying to import a specific function from a module, but the function doesn’t exist in that module.
DeprecationWarning: This is a deprecated feature This warning is issued when you’re using a feature or method that is no longer recommended and may be removed in future versions of Python.
TypeError: ‘NoneType’ object is not subscriptable This error occurs when you’re trying to perform subscription (indexing/slicing) on an object with a value of None.
FileNotFoundError: [Errno 2] No such file or directory: ‘file_path’ This error is raised when you’re trying to access a file that doesn’t exist or the specified file path is incorrect.
OverflowError: int too large to convert to float This error occurs when you’re trying to convert a very large integer to a float, but the integer is too large to be represented as a float.
IndentationError: unexpected indent This error indicates that the indentation of your code is incorrect, usually due to mixing spaces and tabs or inconsistent indentation levels.
IndexError: list index out of range This error is raised when you’re trying to access a list or sequence using an index that is outside the valid range of indices.
KeyError: ‘key’ not found in dictionary This error occurs when you’re trying to access a dictionary using a key that doesn’t exist in the dictionary.
SyntaxError: invalid syntax This error occurs when there is a syntax mistake in your code, such as a missing or misplaced symbol.
NameError: name ‘variable’ is not defined This error occurs when you try to use a variable that hasn’t been assigned a value or is out of scope.
TypeError: unsupported operand type(s) This error indicates that you’re performing an operation on incompatible data types or using unsupported operators.
ValueError: invalid literal for int() with base This error is raised when you’re trying to convert a string to an integer, but the string doesn’t represent a valid integer.
ImportError: No module named ‘module_name’ This error occurs when you’re trying to import a module that cannot be found or doesn’t exist in the specified location.
IndexError: list index out of range This error is raised when you’re trying to access a list or sequence using an index that is outside the valid range of indices.
KeyError: ‘key’ not found in dictionary This error occurs when you’re trying to access a dictionary using a key that doesn’t exist in the dictionary.
FileNotFoundError: [Errno 2] No such file or directory: ‘file_path’ This error is raised when you’re trying to access a file that doesn’t exist or the specified file path is incorrect.
ZeroDivisionError: division by zero This error occurs when you’re trying to divide a number by zero, which is mathematically undefined.
AttributeError: ‘class_name’ object has no attribute ‘attribute_name’ This error indicates that you’re trying to access an attribute or method of an object that doesn’t exist in its class definition.
ValueError: could not convert string to float This error occurs when you’re trying to convert a string to a floating-point number, but the string is not a valid float representation.
AssertionError This error is raised when an assert statement fails, indicating that the specified condition is not true.
IOError: [Errno 13] Permission denied This error occurs when you’re trying to perform a file operation, but you don’t have the necessary permissions to access or modify the file.
RecursionError: maximum recursion depth exceeded This error is raised when a recursive function or method exceeds the maximum recursion depth set in Python.
KeyboardInterrupt: Execution interrupted by the user This error occurs when the user interrupts the program’s execution by pressing Ctrl+C or sending the interrupt signal.
TypeError: ‘type’ object is not iterable This error occurs when you try to iterate over an object that is not iterable, such as an integer or a class.
MemoryError: out of memory This error indicates that the system has run out of memory, usually when trying to allocate memory for a large data structure.
UnicodeError: encoding/decoding error This error occurs when there is an issue with encoding or decoding a Unicode string, such as unsupported characters or incorrect encoding.
ImportError: cannot import name ‘function_name’ from ‘module_name’ This error occurs when you’re trying to import a specific function from a module, but the function doesn’t exist in that module.
DeprecationWarning: This is a deprecated feature This warning is issued when you’re using a feature or method that is no longer recommended and may be removed in future versions of Python.
TypeError: ‘NoneType’ object is not subscriptable This error occurs when you’re trying to perform subscription (indexing/slicing) on an object with a value of None.
FileNotFoundError: [Errno 2] No such file or directory: ‘file_path’ This error is raised when you’re trying to access a file that doesn’t exist or the specified file path is incorrect.
OverflowError: int too large to convert to float This error occurs when

 

By Expert2News

Related Posts