← Back to Error Guide
EOFError

How to Fix EOFError

Raised when the input() function hits an end-of-file condition (EOF) without reading any data.

What is EOFError?

EOFError occurs when one of Python's input functions (like input() or raw_input() in Python 2) tries to read input, but the end of the input stream is reached without receiving any data. This often happens when reading from a file, pipe, or the console, and there is no more data to read.

Common Causes

How to Fix

  1. Check if there is input available before calling input() or read().
  2. Wrap input operations in try-except blocks to handle EOFError gracefully.

Wrong Code

# This code will raise EOFError if no input is provided
user_input = input('Enter something: ')

Correct Code

# This code handles EOFError gracefully
try:
    user_input = input('Enter something: ')
except EOFError:
    print('No input received.')

More Python Error Guides