Pillow Image.open on non-image file: "UnidentifiedImageError: cannot identify image file 'x.txt'"
@aiden-f-dsouza▲ 7 net votes
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.