Skip to content

OSError: [Errno 28] No space left on device

Error message

                [Errno 28] No space left on device
              

Quick summary

An operating system error occurred — the specific subtype (FileNotFoundError, PermissionError, etc.) gives more detail.

Why this happens

  • Disk full (no space left on device)

  • Network issues (connection reset, timeout)

  • Resource limits exceeded (too many open files)

  • Invalid OS-level operations

Minimal example

✗ Broken code
with open('/full_disk/file.txt', 'w') as f:
    f.write('x' * 10**9)  # OSError: No space left on device
✓ Fixed code
try:
    with open('/full_disk/file.txt', 'w') as f:
        f.write('x' * 10**9)
except OSError as e:
    print(f"OS error: {e}")
    # Handle: free space, use different disk, etc.

Catch OSError (or its specific subtype) to handle OS-level failures gracefully.

How to diagnose

  • Read the errno and message for the specific OS error

  • Check system resources (disk space, file descriptors, memory)

  • Verify network connectivity for network operations

How to fix

  • Free up disk space or increase quotas

  • Close unused file handles and connections

  • Handle the specific OSError subtype appropriately

  • Use try/except OSError for general OS error handling

How to prevent

  • Monitor system resources

  • Close files and connections promptly (use context managers)

  • Handle specific OSError subtypes separately

Related Resources

Related Glossary

Related Lessons

← Back to language