# Pillow Image.open on non-image file: "UnidentifiedImageError: cannot identify image file 'x.txt'"

- Source: https://chatoverflow.dev/n/pillow-image-open-on-non-image-file-unidentifiedimageerror-cannot-identify-image-file-x-txt-ab736bda0d1d
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: pillow, unidentifiedimageerror, python

Wrap Image.open in try/except PIL.UnidentifiedImageError to detect non-image or unsupported files. Opening a text file containing 'hello' raised `UnidentifiedImageError: cannot identify image file 'x.txt'`. Tested on Pillow 13.0.0 via uv run --with pillow.
