| |

Common Python Errors and Exceptions

Last Updated on May 9, 2026 by Admin

IndexError / ExceptionMeaningExample
1SyntaxErrorInvalid Python syntaxif x > 5
2IndentationErrorIncorrect indentation after a block statementif x > 5:\nprint(x)
3TabErrorMixed tabs and spaces inconsistentlyUsing tabs on one line and spaces on another
4NameErrorVariable or function not definedprint(price)
5UnboundLocalErrorLocal variable used before assignmentprint(x) inside a function before x = 5
6TypeErrorWrong datatype used in an operation“5” + 2
7ValueErrorCorrect datatype but invalid valueint(“hello”)
8ZeroDivisionErrorDivision by zero10 / 0
9OverflowErrorNumber too large to handlemath.exp(1000)
10IndexErrorList index out of rangenumbers[10]
11KeyErrorDictionary key does not existdata[“name”] when key missing
12AttributeErrorObject does not have that method/attribute5.append(3)
13ImportErrorImport failedfrom math import fake_function
14ModuleNotFoundErrorModule/package not foundimport fake_module
15FileNotFoundErrorFile does not existopen(“missing.txt”)
16PermissionErrorNo permission to access resourceOpening protected file
17IsADirectoryErrorTried to open a directory as a fileopen(“Documents”)
18NotADirectoryErrorExpected directory but got fileUsing file path where folder expected
19RuntimeErrorGeneral runtime problemInvalid runtime state
20RecursionErrorToo many recursive function callsFunction calling itself forever
21AssertionErrorassert statement failedassert x > 10
22StopIterationIterator has no more valuesCalling next() past the end
23MemoryErrorProgram ran out of memoryCreating extremely large list
24KeyboardInterruptUser interrupted program (Ctrl+C)Stopping infinite loop manually
25SystemExitProgram exited intentionallyexit()
26EOFErrorUnexpected end of inputinput() with no input stream
27UnicodeEncodeErrorFailed converting Unicode to bytesUnsupported character encoding
28UnicodeDecodeErrorFailed decoding bytes to textReading file with wrong encoding
29ConnectionErrorGeneral network connection issueFailed internet/socket connection
30ConnectionRefusedErrorRemote host rejected connectionConnecting to closed server port
31TimeoutErrorOperation took too longNetwork request timeout
32BrokenPipeErrorWriting to closed connectionSending data after disconnect
33FloatingPointErrorFloating-point calculation failedNumerical overflow/invalid operation
34BufferErrorBuffer-related operation failedResizing active buffer
35ReferenceErrorWeak reference refers to deleted objectAccessing destroyed referenced object
36SystemErrorInternal Python interpreter issueRare low-level interpreter fault
37NotImplementedErrorMethod/function intentionally unfinishedPlaceholder method in class
38OSErrorOperating system related issueFile/device/system call failure
39LookupErrorBase class for lookup problemsParent of IndexError and KeyError
40ArithmeticErrorBase class for arithmetic issuesParent of division/overflow errors
41UnicodeErrorBase class for Unicode issuesParent of Unicode exceptions

Similar Posts