EOFError
PythonERRORNotableIOHIGH confidence

End of file reached

Production Risk

Common in automation pipelines; always handle EOFError when reading from stdin.

What this means

Raised when input() reaches the end of the input stream (EOF) without reading any data. Common in scripts that read from stdin when there is no more input.

Why it happens
  1. 1input() called in a script piped from a file or process that has ended
  2. 2Interactive session closed while waiting for input()
  3. 3Reading from stdin in a Docker container or CI environment with no TTY
How to reproduce

Script calls input() when stdin is a closed pipe.

trigger — this will error
trigger — this will error
echo "" | python3 -c "name = input('Name: ')"

expected output

Traceback (most recent call last):
  File "<string>", line 1, in <module>
EOFError: EOF when reading a line

Fix 1

Wrap input() in a try/except

WHEN Script reads from stdin that may be closed

Wrap input() in a try/except
try:
    line = input("Name: ")
except EOFError:
    line = ""  # or use a default, or exit

Why this works

Catching EOFError lets the script handle piped or redirected input gracefully.

Fix 2

Use sys.stdin.read() for batch input

WHEN Reading all stdin at once

Use sys.stdin.read() for batch input
import sys
data = sys.stdin.read()  # returns "" at EOF, no exception

Why this works

sys.stdin.read() returns an empty string at EOF rather than raising EOFError.

Code examples
Triggerpython
# echo "" | python3 -c "name = input()"
# EOFError: EOF when reading a line
Handle with try/exceptpython
try:
    line = input("> ")
except EOFError:
    line = ""  # no input available
Avoid with sys.stdin.read()python
import sys
data = sys.stdin.read()  # returns "" at EOF without raising
Sources
Official documentation ↗

Python Docs — Built-in Exceptions

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Python errors