0

I'm trying to load image from the internet.

from PIL import Image

Image.open("https://i.etsystatic.com/8331303/r/il/dec4ed/2753449716/il_300x300.2753449716_i5j3.jpg")

then this error below.

---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<ipython-input-14-d6dfd73d2382> in <module>
      1 from PIL import Image
----> 2 Image.open("https://i.etsystatic.com/8331303/r/il/dec4ed/2753449716/il_300x300.2753449716_i5j3.jpg")

~\anaconda3\lib\site-packages\PIL\Image.py in open(fp, mode, formats)
   2910 
   2911     if filename:
-> 2912         fp = builtins.open(filename, "rb")
   2913         exclusive_fp = True
   2914 

OSError: [Errno 22] Invalid argument: 'https://i.etsystatic.com/8331303/r/il/dec4ed/2753449716/il_300x300.2753449716_i5j3.jpg'

I found out that files on my computer can be loaded by writing the path like c:/.../ . But writing the path like http://... returns error. How to load an image from the internet?

1
  • How would it know to fetch it from the Internet? Commented Sep 11, 2021 at 21:32

1 Answer 1

0

You can use this:

from PIL import Image
import requests
from io import BytesIO

response = requests.get(url)
img = Image.open(BytesIO(response.content))
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.