PythonMastery
Error reference

Python errors, explained

45 errors you will actually meet, each with what Python is complaining about, the code that causes it, and the fix. Every example runs in the browser — break it, read the traceback, repair it, run it again.

Holding the exact message? Find its family below. Only know when it broke? Browse by when it happens.

By error type

28 families

TypeError8

AttributeError3

RuntimeError3

ValueError3

ImportError2

IndentationError2

IndexError2

OSError2

'python' is not recognized as an internal or external command1

ConnectionRefusedError1

FileNotFoundError1

KeyError1

  • KeyError: 'X'

    A KeyError is raised when you try to access a key in a dictionary (or a dict-like object) that does not exist.

MemoryError1

ModuleNotFoundError1

  • ModuleNotFoundError: No module named 'X'

    The import machinery walked every entry in sys.path — your script's directory, the standard library, site-packages — and could not find a package or module called X.

NameError1

PermissionError1

RecursionError1

SSLCertVerificationError1

SyntaxError1

TabError1

TimeoutError / requests.exceptions.ReadTimeout1

UnboundLocalError1

UnicodeDecodeError1

UnicodeEncodeError1

ZeroDivisionError1

error1

json.JSONDecodeError1

socket.gaierror1

By when it happens

same 45 errors, different way in
nextStill stuck?

An error not listed here usually means the traceback is pointing somewhere other than where the mistake is. Errors & Exceptions covers how to read one properly, and Exceptions: Patterns Beyond the Basics covers raising your own.