🐍 Python Errors

50 error notes

pythonintermediate

How to Fix 'sqlite3.OperationalError: database is locked' in Python

sqlite3.OperationalError: database is locked
pythonsqlitedatabasesqlite3
pythonbeginner

Fixing 'AttributeError: module collections has no attribute Callable' in Python 3.10+

AttributeError: module 'collections' has no attribute 'Callable'
pythoncollectionspython310backend
pythonbeginner

How to Fix 'TypeError: 'dict_keys' object is not subscriptable' in Python

TypeError: 'dict_keys' object is not subscriptable
pythondebuggingdictionarytypeerror
pythonintermediate

Fixing 'RuntimeError: no running event loop' in Python 3.10, 3.11, and 3.12

RuntimeError: no running event loop
pythonasyncioevent-loopconcurrency
pythonbeginner

Fixing the Python Multiprocessing 'RuntimeError' on Windows

RuntimeError: An attempt has been made to start a new process before the current process has finished its bootstrapping phase
pythonmultiprocessingwindowsdebugging
pythonintermediate

Fixing SQLAlchemy PendingRollbackError: Stop the 'Poisoned Session' Cycle

sqlalchemy.exc.PendingRollbackError: Can't reconnect until invalid transaction is rolled back
pythonsqlalchemyfastapidatabase-errors
pythonintermediate

How to Fix NumPy's 'ValueError: operands could not be broadcast together'

ValueError: operands could not be broadcast together with shapes (3,) (4,)
pythonnumpybroadcastingdata-science
pythonbeginner

Fixing 'SyntaxError: f-string expression part cannot include a backslash' in Python

SyntaxError: f-string expression part cannot include a backslash
pythonf-stringsyntaxerrorcoding-tips
pythonbeginner

Fixing the 'Microsoft Visual C++ 14.0 or greater is required' Error on Windows

error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
pipwindowsvisual-c++python-errors
pythonbeginner

Handling ZeroDivisionError in Python: Practical Fixes and Prevention

ZeroDivisionError: division by zero
pythondebuggingpandasnumpy
pythonbeginner

Fix OSError: [Errno 98] Address already in use in Flask and FastAPI

OSError: [Errno 98] Address already in use
pythonflaskfastapisocket
pythonbeginner

Fix Python ValueError: could not convert string to float '1,234' β€” Locale Number Formats

ValueError: could not convert string to float: '1,234'
pythonfloatstringpandas
pythonintermediate

Fix 'RuntimeError: Working outside of application context' in Flask

RuntimeError: Working outside of application context. This typically means that you attempted to use functionality that needed to interface with the current application object in some way.
flaskpythonapp-contextruntimeerror
pythonbeginner

Fix TypeError: 'type' object is not subscriptable in Python Type Hints

TypeError: 'type' object is not subscriptable
pythontype-hintstypeerrortyping
pythonbeginner

Fixing 'TypeError: Object of type datetime is not JSON serializable' in Python

TypeError: Object of type datetime is not JSON serializable
pythonjsondatetimeserialization
pythonintermediate

Fixing 'ConnectionRefusedError: [Errno 111] Connection refused' in Python

ConnectionRefusedError: [Errno 111] Connection refused
pythonsocketdockerlinux
pythonbeginner

How to Fix 'TypeError: list indices must be integers or slices, not str' in Python

TypeError: list indices must be integers or slices, not str
pythondebuggingjsonbackend
pythonbeginner

Fixing Python's 'can't compare offset-naive and offset-aware datetimes' Error

TypeError: can't compare offset-naive and offset-aware datetimes
pythondatetimetimezonedjango
pythonbeginner

Fixing 'IndexError: list index out of range' in Python

IndexError: list index out of range
pythonlistindexerrordebugging
pythonintermediate

Fixing 'TypeError: cannot pickle' in Python Multiprocessing

TypeError: cannot pickle '<lambda>' object
pythonmultiprocessingpickleparallel
pythonbeginner

Fix 'TypeError: method() takes 1 positional argument but 2 were given' in Python

TypeError: my_method() takes 1 positional argument but 2 were given
pythonooptypeerrorclass
pythonbeginner

Fix 'error: externally-managed-environment' When Installing Python Packages with pip

error: externally-managed-environment
pythonpiplinuxvirtualenv
pythonbeginner

Fixing 'UnboundLocalError: local variable referenced before assignment' in Python

UnboundLocalError: local variable 'x' referenced before assignment
pythonvariable scopeunboundlocalerrorglobal
pythonbeginner

Solving Python's 'FileNotFoundError: [Errno 2]' Once and For All

FileNotFoundError: [Errno 2] No such file or directory: 'path/to/file.txt'
pythondebuggingpathlibfile-handling
pythonbeginner

Fixing the 'ParserError: Error tokenizing data' in Pandas

pandas.errors.ParserError: Error tokenizing data. C error: Expected 3 fields in line 12, saw 5
pythonpandascsvdata-science
pythonintermediate

Fix OSError: [Errno 24] Too many open files in Python

OSError: [Errno 24] Too many open files
pythonoserrorfile-descriptorresource-limit
pythonintermediate

Fix 'OverflowError: math range error' in Python with math.exp() and Large Numbers

OverflowError: math range error
pythonmathoverflowfloat
pythonintermediate

Fix 'JSONDecodeError: Expecting value: line 1 column 1 (char 0)' in Python

json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
pythonjsonjsondecodeerrorparsing
pythonbeginner

Fixing Python's PermissionError: [Errno 13] Permission Denied

PermissionError: [Errno 13] Permission denied: '/path/to/file'
pythonfile-handlingdevopstroubleshooting
pythonintermediate

Solving the Pandas SettingWithCopyWarning: Why Your DataFrame Updates Fail

SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame
pythonpandasdataframedata-science
pythonbeginner

Fix TypeError: 'NoneType' object is not iterable in Python

TypeError: 'NoneType' object is not iterable
pythontypeerrornoneiteration
pythonbeginner

Fixing Python’s 'ValueError: invalid literal for int() with base 10'

ValueError: invalid literal for int() with base 10: 'abc'
pythonvalueerrordata-cleaningbackend
pythonintermediate

Fixing the Python 'Max retries exceeded' ConnectionError

requests.exceptions.ConnectionError: HTTPSConnectionPool(host='...', port=443): Max retries exceeded with url
pythonrequestsapi-developmentnetworking
pythonintermediate

Stop the Crash: Fixing 'RuntimeError: generator raised StopIteration' in Python 3.7+

RuntimeError: generator raised StopIteration
pythongeneratorstopiterationpep479
pythonintermediate

Fixing 'UnicodeEncodeError: ascii codec can't encode character' in Python

UnicodeEncodeError: 'ascii' codec can't encode character '\u00e9' in position 1: ordinal not in range(128)
pythonunicodeencodingascii
pythonintermediate

Fix subprocess.CalledProcessError: Command Returned Non-Zero Exit Status in Python

subprocess.CalledProcessError: Command '['...']' returned non-zero exit status 1
pythonsubprocessshellprocess
pythonbeginner

Fix 'RuntimeWarning: coroutine was never awaited' in Python async/await

RuntimeWarning: coroutine 'xxx' was never awaited
pythonasynciocoroutineasync
pythonbeginner

Fix RuntimeError: dictionary changed size during iteration in Python

RuntimeError: dictionary changed size during iteration
pythonruntimeerrordictionaryiteration
pythonbeginner

Fix TypeError: unsupported operand type(s) for +: 'int' and 'str' in Python

TypeError: unsupported operand type(s) for +: 'int' and 'str'
pythontypeerrortype-conversiondebugging
pythonintermediate

Fix ImportError: cannot import name from partially initialized module (circular import) in Python

ImportError: cannot import name 'X' from partially initialized module 'Y' (most likely due to a circular import)
pythonimportcircular-importmodule
pythonbeginner

Fix Python UnicodeDecodeError: 'utf-8' codec can't decode byte

UnicodeDecodeError: 'utf-8' codec can't decode byte
pythonunicodeencoding
pythonintermediate

Fix Python MemoryError When Processing Large Data

MemoryError
pythonmemoryperformancelarge-data
pythonbeginner

Fix ssl.SSLCertVerificationError: certificate verify failed in Python HTTPS Requests

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)
pythonsslrequestshttps
pythonbeginner

Fix Python KeyError: 'key_name' When Accessing a Dictionary

KeyError: 'key_name'
pythonkeyerrordictionary
pythonintermediate

Fix Python RecursionError: maximum recursion depth exceeded

RecursionError: maximum recursion depth exceeded
pythonrecursionsys
pythonbeginner

Fix Python TypeError: 'str' object is not callable

TypeError: 'str' object is not callable
pythontypeerrorfunctionvariable
pythonbeginner

Fix Python ValueError: too many values to unpack (expected 2)

ValueError: too many values to unpack (expected 2)
pythontupleunpackinglist
pythonbeginner

Fix AttributeError: 'NoneType' object has no attribute in Python

AttributeError: 'NoneType' object has no attribute 'split'
pythonattributeerrornonetypedebugging
pythonbeginner

Fix 'IndentationError: expected an indented block' in Python

IndentationError: expected an indented block
pythonindentationsyntax
pythonbeginner

Fix ModuleNotFoundError: No module named 'xxx' in Python

ModuleNotFoundError: No module named 'xxx'
pythonpipimportvirtualenv