OSError: cannot identify image file. Being thrown by torchserve on a POST request with image file

DeepManuPy: <pre><code class="lang-auto">2021-03-18 18:09:59,230 [INFO ] W-9000-WasteNet_1.0 org.pytorch.serve.wlm.WorkerThread - Backend response time: 3
2021-03-18 18:09:59,232 [INFO ] W-9000-WasteNet_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - Traceback (most recent call last):
2021-03-18 18:09:59,233 [INFO ] W-9000-WasteNet_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle -   File "c:\users\mchintha\anaconda\lib\site-packages\ts\service.py", line 100, in predict
2021-03-18 18:09:59,233 [INFO ] W-9000-WasteNet_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle -     ret = self._entry_point(input_batch, self.context)
2021-03-18 18:09:59,234 [INFO ] W-9000-WasteNet_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle -   File "c:\users\mchintha\anaconda\lib\site-packages\ts\torch_handler\base_handler.py", line 125, in handle
2021-03-18 18:09:59,234 [INFO ] W-9000-WasteNet_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle -     data = self.preprocess(data)
2021-03-18 18:09:59,235 [INFO ] W-9000-WasteNet_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle -   File "c:\users\mchintha\anaconda\lib\site-packages\ts\torch_handler\vision_handler.py", line 21, in preprocess
2021-03-18 18:09:59,236 [INFO ] W-9000-WasteNet_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle -     image = Image.open(io.BytesIO(image))
2021-03-18 18:09:59,237 [DEBUG] W-9000-WasteNet_1.0 org.pytorch.serve.wlm.Job - Waiting time ns: 165300, Inference time ns: 8981200
2021-03-18 18:09:59,237 [INFO ] W-9000-WasteNet_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle -   File "c:\users\mchintha\anaconda\lib\site-packages\PIL\Image.py", line 2622, in open
2021-03-18 18:09:59,238 [INFO ] W-9000-WasteNet_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle -     % (filename if filename else fp))
2021-03-18 18:09:59,238 [INFO ] W-9000-WasteNet_1.0-stdout org.pytorch.serve.wlm.WorkerLifeCycle - OSError: cannot identify image file &lt;_io.BytesIO object at 0x00000236FC0D6D00&gt;
</code></pre>
<p>Torchserve is throwing this error when I send an HTTP POST request on Windows OS.<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/f/b/fb9b0b93618f565200867b9004b3b03070adf69c.png" data-download-href="https://discuss.pytorch.org/uploads/default/fb9b0b93618f565200867b9004b3b03070adf69c" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/f/b/fb9b0b93618f565200867b9004b3b03070adf69c_2_690x319.png" alt="image" data-base62-sha1="zTO1JmmyIAEFZe0KwMEc5BnYODO" width="690" height="319" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/f/b/fb9b0b93618f565200867b9004b3b03070adf69c_2_690x319.png, https://discuss.pytorch.org/uploads/default/original/3X/f/b/fb9b0b93618f565200867b9004b3b03070adf69c.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/f/b/fb9b0b93618f565200867b9004b3b03070adf69c.png 2x" data-dominant-color="282928"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">839×389 27.8 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>However, when I ran the Torchserve on a Linux OS. It is working just fine.</p>
<pre><code class="lang-auto">curl -X POST http://localhost:8443/predictions/WasteNet -T R_10396.jpg
</code></pre>
<p>It returned the predictions in a JSON format as expected.<br>
I’ve used the same static files for running torchserve on both the OS. I was wondering if this is an OS error rather than a torchserve internal error.</p>

ptrblck: <p>Could you add debug print statements and check which file path is being loaded and fails?<br>
Since this issue seems to be OS-dependent I guess the image file is either corrupt (during the copying) or some hidden or system files might be found on one OS and yield this error.</p>