EOFE python io_error ai_generated true

EOFError: EOF when reading a line

ID: python/eofeerror-unexpected

Also available as: JSON · Markdown
90%Fix Rate
90%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
311 active

Root Cause

input() called but stdin is closed/empty. Common in Docker, piped input, or automated scripts.

generic

Workarounds

  1. 92% success Wrap in try/except EOFError for graceful handling
    try:
        line = input()
    except EOFError:
        line = ''

    Sources: https://docs.python.org/3/library/functions.html#input

  2. 88% success Use sys.stdin with check: for line in sys.stdin:
    for line in sys.stdin:

    Sources: https://docs.python.org/3/library/sys.html#sys.stdin

Dead Ends

Common approaches that don't work:

  1. Add a default value to input() 75% fail

    input() doesn't support defaults — need try/except

Error Chain

Frequently confused with: