I am running the following code:
import requests
from PIL import Image
try:
aux_im = Image.open(requests.get('https://www.bimbaylola.com/media/catalog/product/1/8/182BAC104_T2200_P_T_XX_1.jpg', stream=True).raw)
except Exception as e:
print(str(e))
And getting the following error:
cannot identify image file <_io.BytesIO object at 0x1118918e0>
Any ideas why is this happening?
Thanks in advance!
My suggestion is
import io
import requests
from PIL import Image
r = requests.get('https://www.bimbaylola.com/media/catalog/product/1/8/182BAC104_T2200_P_T_XX_1.jpg', stream=True)
aux_im = Image.open(io.BytesIO(r.content))
My suggestion is
import io import requests from PIL import Image r = requests.get('https://www.bimbaylola.com/media/catalog/product/1/8/182BAC104_T2200_P_T_XX_1.jpg', stream=True) aux_im = Image.open(io.BytesIO(r.content))
It worked! Thank you!
My suggestion is
import io import requests from PIL import Image r = requests.get('https://www.bimbaylola.com/media/catalog/product/1/8/182BAC104_T2200_P_T_XX_1.jpg', stream=True) aux_im = Image.open(io.BytesIO(r.content))It didn't worked! For Below Image URl
https://www.showbizpizza.com/photos/cec/tx_roundrock/14.jpg
Its throwing error like
cannot identify image file <_io.BytesIO object at 0x03323450>
@rahultrimukhe777 your code works for me. Could you provide some more details? Are you using the latest version of Pillow?
Name: Pillow
Version: 6.1.0
Summary: Python Imaging Library (Fork)
Home-page: http://python-pillow.org
Author: Alex Clark (Fork Author)
Author-email: [email protected]
License: UNKNOWN
I am on [email protected] and seeing the same error with the following script
from PIL import Image
import PIL.ImageOps
import requests
import io
imgUrl = "https://raw.githubusercontent.com/frogermcs/MNIST-TFLite/master/notebooks/test.png"
r = requests.get(imgUrl, stream=True)
img = Image.open(io.BytesIO(r.content))
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-75-ac6c92e8d1e0> in <module>()
6 imgUrl = "https://raw.githubusercontent.com/frogermcs/MNIST-TFLite/master/notebooks/test.png"
7 r = requests.get(imgUrl, stream=True)
----> 8 img = Image.open(io.BytesIO(r.content))
~/Library/Python/3.6/lib/python/site-packages/PIL/Image.py in open(fp, mode)
2820 for message in accept_warnings:
2821 warnings.warn(message)
-> 2822 raise IOError("cannot identify image file %r" % (filename if filename else fp))
2823
2824
OSError: cannot identify image file <_io.BytesIO object at 0x110f1ea98>
@amrish7 your code works for me. (Windows 7 Python 3.7.3 64-bit Pillow 6.1.0)
@nitinsunny Works for me on macOS:
Python 3.9.0 (v3.9.0:9cf6752276, Oct 5 2020, 11:29:23)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import io
>>> import requests
>>> from PIL import Image
>>> r = requests.get('https://www.bimbaylola.com/media/catalog/product/1/8/182BAC104_T2200_P_T_XX_1.jpg', stream=True)
>>> aux_im = Image.open(io.BytesIO(r.content))
>>> aux_im.show()
>>> r = requests.get('https://assets.hyatt.com/content/dam/hyatt/hyattdam/images/2019/02/05/1047/Chase-World-of-Hyatt-Credit-Card-Contactless-Card.png/Chase-World-of-Hyatt-Credit-Card-Contactless-Card.360x159.png?imwidth=640', stream=True)
>>> aux_im = Image.open(io.BytesIO(r.content))
>>> aux_im.show()
>>> Image.__version__
'8.0.0'
>>>
Please open a new issue with more details if it persists.
Most helpful comment
My suggestion is