Image.open()需要文件名或类似文件的对象-而不是文件数据。
您可以在本地写入图像(即为
"temp.jpg"-),然后将其打开
from PIL import Imageimport urllib.requestURL = 'http://www.w3schools.com/css/trolltunga.jpg'with urllib.request.urlopen(URL) as url: with open('temp.jpg', 'wb') as f: f.write(url.read())img = Image.open('temp.jpg')img.show()或者您可以使用
io模块在内存中创建类似文件的对象
from PIL import Imageimport urllib.requestimport ioURL = 'http://www.w3schools.com/css/trolltunga.jpg'with urllib.request.urlopen(URL) as url: f = io.BytesIO(url.read())img = Image.open(f)img.show()



