Common Python Errors and Exceptions
Last Updated on May 9, 2026 by Admin
| Index | Error / Exception | Meaning | Example |
|---|---|---|---|
| 1 | SyntaxError | Invalid Python syntax | if x > 5 |
| 2 | IndentationError | Incorrect indentation after a block statement | if x > 5:\nprint(x) |
| 3 | TabError | Mixed tabs and spaces inconsistently | Using tabs on one line and spaces on another |
| 4 | NameError | Variable or function not defined | print(price) |
| 5 | UnboundLocalError | Local variable used before assignment | print(x) inside a function before x = 5 |
| 6 | TypeError | Wrong datatype used in an operation | “5” + 2 |
| 7 | ValueError | Correct datatype but invalid value | int(“hello”) |
| 8 | ZeroDivisionError | Division by zero | 10 / 0 |
| 9 | OverflowError | Number too large to handle | math.exp(1000) |
| 10 | IndexError | List index out of range | numbers[10] |
| 11 | KeyError | Dictionary key does not exist | data[“name”] when key missing |
| 12 | AttributeError | Object does not have that method/attribute | 5.append(3) |
| 13 | ImportError | Import failed | from math import fake_function |
| 14 | ModuleNotFoundError | Module/package not found | import fake_module |
| 15 | FileNotFoundError | File does not exist | open(“missing.txt”) |
| 16 | PermissionError | No permission to access resource | Opening protected file |
| 17 | IsADirectoryError | Tried to open a directory as a file | open(“Documents”) |
| 18 | NotADirectoryError | Expected directory but got file | Using file path where folder expected |
| 19 | RuntimeError | General runtime problem | Invalid runtime state |
| 20 | RecursionError | Too many recursive function calls | Function calling itself forever |
| 21 | AssertionError | assert statement failed | assert x > 10 |
| 22 | StopIteration | Iterator has no more values | Calling next() past the end |
| 23 | MemoryError | Program ran out of memory | Creating extremely large list |
| 24 | KeyboardInterrupt | User interrupted program (Ctrl+C) | Stopping infinite loop manually |
| 25 | SystemExit | Program exited intentionally | exit() |
| 26 | EOFError | Unexpected end of input | input() with no input stream |
| 27 | UnicodeEncodeError | Failed converting Unicode to bytes | Unsupported character encoding |
| 28 | UnicodeDecodeError | Failed decoding bytes to text | Reading file with wrong encoding |
| 29 | ConnectionError | General network connection issue | Failed internet/socket connection |
| 30 | ConnectionRefusedError | Remote host rejected connection | Connecting to closed server port |
| 31 | TimeoutError | Operation took too long | Network request timeout |
| 32 | BrokenPipeError | Writing to closed connection | Sending data after disconnect |
| 33 | FloatingPointError | Floating-point calculation failed | Numerical overflow/invalid operation |
| 34 | BufferError | Buffer-related operation failed | Resizing active buffer |
| 35 | ReferenceError | Weak reference refers to deleted object | Accessing destroyed referenced object |
| 36 | SystemError | Internal Python interpreter issue | Rare low-level interpreter fault |
| 37 | NotImplementedError | Method/function intentionally unfinished | Placeholder method in class |
| 38 | OSError | Operating system related issue | File/device/system call failure |
| 39 | LookupError | Base class for lookup problems | Parent of IndexError and KeyError |
| 40 | ArithmeticError | Base class for arithmetic issues | Parent of division/overflow errors |
| 41 | UnicodeError | Base class for Unicode issues | Parent of Unicode exceptions |