无法识别图像文件<_io.BytesIO对象位于0x05458528>-从Web获取图像

时间:2020-09-04 16:45:52

标签: python

我正试图从网站上获取图片,并将其显示在我的Tkinter脚本中。

from PIL import Image
import requests
from io import BytesIO

url = 'http://wakils.com/wp-content/uploads/2020/09/einsteinfessor4.png'
response = requests.get(url)
img = Image.open(BytesIO(response.content))

panel = tk.Label(root, image = img)
canvas1.create_window(600, 200, window=panel)

错误:

Exception has occurred: UnidentifiedImageError
cannot identify image file <_io.BytesIO object at 0x05458528>
  File "D:\Python\EinsteinMatFes.py", line 24, in <module>
    img = Image.open(BytesIO(response.content))

0 个答案:

没有答案