# Imread fails with unknown exception

**URL:** <https://forum.opencv.org/t/imread-fails-with-unknown-exception/6841>\
**Category:** Python\
**Tags:** imgcodecs\
**Created:** [December 22, 2021, 12:08pm UTC](https://forum.opencv.org/t/imread-fails-with-unknown-exception/6841 "2021-12-22T12:08:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ebeyabraham](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/ebeyabraham/32/4069_2.png) [@ebeyabraham](https://forum.opencv.org/u/ebeyabraham)\
**Post date:** [December 22, 2021, 12:08pm UTC](https://forum.opencv.org/t/imread-fails-with-unknown-exception/6841/1 "2021-12-22T12:08:28Z")

</div>

Hi, I am using imread to read .exr images as

```auto
img = cv2.imread(img_path, cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH)

```

which works most of the time, but sometime randomly it fails with the following error

```auto
imread_('filename.exr'): can't read data: unknown exception

```

I have tried looping over all images multiple times and reading them. Sometimes I am able to read all images without any error, and sometime I get such errors. Any idea why this may be happening or any way I can try and fix this.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [December 22, 2021, 2:19pm UTC](https://forum.opencv.org/t/imread-fails-with-unknown-exception/6841/2 "2021-12-22T14:19:39Z")

</div>

possible bug. what version of OpenCV do you use? can you provide a minimal reproducible example, including sample data?

---

<div class="post-metadata">

**Author:** ![alekseynp](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/alekseynp/32/4411_2.png) [@alekseynp](https://forum.opencv.org/u/alekseynp)\
**Post date:** [February 3, 2022, 5:14pm UTC](https://forum.opencv.org/t/imread-fails-with-unknown-exception/6841/3 "2022-02-03T17:14:33Z")

</div>

I am as of this month experiencing the same problem with code that was working before.

I am on:

```bash
$ conda list | grep opencv
opencv-python 4.5.4.60 pypi_0 pypi
opencv-python-headless 4.5.4.60 pypi_0 pypi

$ python -V
Python 3.8.8

```

I `cv2.imwrite` and `cv2.imread` thousands of `.exr` files.

I have found that I can sometimes write retry logic that checks if the return from `cv2.imread` `is None` and read again successfully. I have also found cases where this doesn’t work. I have found that when I have a file that is never successfully read with `cv2.imread` I also fail to open that file with Gimp, unlike one of my normal files.

I recently added a check where on the line immediately following `cv2.imwrite` I attempt a `cv2.imread` and have had that read fail. I have been wondering if I have a failing drive.

---

<div class="post-metadata">

**Author:** ![alekseynp](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/alekseynp/32/4411_2.png) [@alekseynp](https://forum.opencv.org/u/alekseynp)\
**Post date:** [March 24, 2022, 3:43pm UTC](https://forum.opencv.org/t/imread-fails-with-unknown-exception/6841/4 "2022-03-24T15:43:27Z")

</div>

I should follow-up to say that I ended up swapping out my RAM And this problem went away. In hindsight my system was suffering other issues related to that bad RAM.
