Python Error Reference
A comprehensive collection of common Python exceptions, their causes, and how to fix them.
assert 1 == 2...
Learn how to resolve the AssertionError in Python. Assertion failed. Check your assumption....
[1, 2, 3].push(4)...
Learn how to resolve the AttributeError in Python. List object has no attribute 'push'. Did you mean ...
None.some_method()...
Learn how to resolve the AttributeError in Python. 'NoneType' object has no attribute 'some_method'....
os.write(fd, data)...
Learn how to resolve the BlockingIOError in Python. Resource temporarily unavailable (non-blocking I/O...
socket.connect(('localhost', 8...
Learn how to resolve the ConnectionRefusedError in Python. Connection refused. Check server status and port....
import imp...
Learn how to resolve the DeprecationWarning in Python. imp module is deprecated. Use importlib....
input('')...
Learn how to resolve the EOFError in Python. End of file reading input (e.g. user pressed Ctrl+...
os.makedirs('existing_dir')...
Learn how to resolve the FileExistsError in Python. File exists: 'existing_dir'. Handle existence or u...
open('missing.txt')...
Learn how to resolve the FileNotFoundError in Python. The file 'missing.txt' was not found. Check the pa...
1.0 / 0.0...
Learn how to resolve the FloatingPointError in Python. Float division by zero (usually raises ZeroDivisio...
import unknown_module...
Learn how to resolve the ImportError in Python. No module named 'unknown_module'. Check installati...
def my_func(): print('hello')...
Learn how to resolve the IndentationError in Python. The body of the function must be indented....
expected an indented block...
Learn how to resolve the IndentationError in Python. Missing indentation after 'if' or 'def'....
my_list = [1, 2, 3]; print(my_...
Learn how to resolve the IndexError in Python. List index out of range. Check the list length....
open('/tmp', 'r')...
Learn how to resolve the IsADirectoryError in Python. Is a directory: '/tmp'. Cannot open directory as f...
while True: pass...
Learn how to resolve the KeyboardInterrupt in Python. User interrupted execution (Ctrl+C)....
my_dict = {'a': 1}; print(my_d...
Learn how to resolve the KeyError in Python. Key 'b' is not in the dictionary. Use .get() or ch...
os.environ['MISSING_ENV']...
Learn how to resolve the KeyError in Python. Environment variable not found....
codecs.lookup('unknown')...
Learn how to resolve the LookupError in Python. Unknown encoding....
x = [1] * (10**10)...
Learn how to resolve the MemoryError in Python. Out of memory. Optimize data structures or algorit...
import non_existent...
Learn how to resolve the ModuleNotFoundError in Python. No module named 'non_existent'. Install it via pip...
print(undefined_var)...
Learn how to resolve the NameError in Python. The variable 'undefined_var' is not defined. Ensur...
os.listdir('/etc/hosts')...
Learn how to resolve the NotADirectoryError in Python. Not a directory: '/etc/hosts'....
def foo(): raise NotImplemente...
Learn how to resolve the NotImplementedError in Python. This method is not implemented yet....
os.remove('non_existent')...
Learn how to resolve the OSError in Python. No such file or directory....
import math; math.exp(1000)...
Learn how to resolve the OverflowError in Python. Math result too large. Handle large numbers or lim...
open('/root/secret', 'r')...
Learn how to resolve the PermissionError in Python. Permission denied. Check file permissions....
def foo(): foo(); foo()...
Learn how to resolve the RecursionError in Python. Maximum recursion depth exceeded. Check base case ...
import weakref; r = weakref.re...
Learn how to resolve the ReferenceError in Python. Weakly-referenced object no longer exists....
recursion limit...
Learn how to resolve the RuntimeError in Python. Maximum recursion depth exceeded (can be RuntimeEr...
it = iter([1]); next(it); next...
Learn how to resolve the StopIteration in Python. Iterator has no further items. Catch StopIteration...
def function(a, b):...
Learn how to resolve the SyntaxError in Python. Missing body or 'pass'....
if x = 5:...
Learn how to resolve the SyntaxError in Python. Invalid syntax. Use == for comparison....
print 'Hello World'...
Learn how to resolve the SyntaxError in Python. In Python 3, print is a function. Use print('Hello...
return...
Learn how to resolve the SyntaxError in Python. Return outside function....
sys.exit()...
Learn how to resolve the SystemError in Python. SystemError can happen on internal errors, but sys...
def foo(): print('x') pri...
Learn how to resolve the TabError in Python. Inconsistent use of tabs and spaces in indentation...
socket.timeout...
Learn how to resolve the TimeoutError in Python. The operation timed out....
'a' - 'b'...
Learn how to resolve the TypeError in Python. Unsupported operand type(s) for -: 'str' and 'str'...
'Age: ' + 25...
Learn how to resolve the TypeError in Python. Cannot concatenate string and integer. Use str(25)...
len(123)...
Learn how to resolve the TypeError in Python. Object of type 'int' has no len(). len() works on ...
list['a']...
Learn how to resolve the TypeError in Python. Type 'type' is not subscriptable (in older Python ...
None + 1...
Learn how to resolve the TypeError in Python. Unsupported operand type(s) for +: 'NoneType' and ...
raise 'Error'...
Learn how to resolve the TypeError in Python. Exceptions must derive from BaseException. Use rai...
x = 10; def foo(): print(x); x...
Learn how to resolve the UnboundLocalError in Python. Local variable 'x' referenced before assignment. U...
b''.decode('utf-8')...
Learn how to resolve the UnicodeDecodeError in Python. 'utf-8' codec can't decode byte 0x80. Check encodi...
'�'.encode('ascii')...
Learn how to resolve the UnicodeEncodeError in Python. 'ascii' codec can't encode character. Use 'utf-8'....
int('hello')...
Learn how to resolve the ValueError in Python. Invalid literal for int() with base 10. Ensure the...
list.remove(x)...
Learn how to resolve the ValueError in Python. x not in list....
result = 10 / 0...
Learn how to resolve the ZeroDivisionError in Python. Division by zero is not allowed. Check your diviso...