user58653
user58653

Reputation: 55

Object has no attribute 'Read' Error: PIL Library

I am trying to load an image from a specific URL using the Image.Open() method from the PIL library, however I am getting the following error:

'Response' object has no attribute 'read'

My code is as follows:

image1 = Image.open(requests.get(URL))

Upvotes: 1

Views: 1046

Answers (1)

MattDMo
MattDMo

Reputation: 102862

This is addressed in the requests Quickstart:

from PIL import Image
from io import BytesIO

i = Image.open(BytesIO(r.content))

where r is a Response object such that r = requests.get(URL).

Upvotes: 1

Related Questions