python system_error official true

OSError

ID: python/oserror

Also available as: JSON · Markdown
80%Fix Rate
95%Confidence
0Evidence

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

An operating system error occurred. This is the base class for many system-level errors. Check the .errno and .strerror attributes.

generic

Official Documentation

https://docs.python.org/3/library/exceptions.html

Workarounds

  1. 90% success Check e.errno to determine the specific OS error code and handle accordingly
    except OSError as e: if e.errno == errno.ENOSPC: ...
  2. 90% success Check file/directory permissions with os.access() before operations
    os.access(path, os.R_OK | os.W_OK)

Dead Ends

Common approaches that don't work:

  1. Ignoring all OSError exceptions 80% fail

    System errors (disk full, permission denied) need proper handling