编程语言
首页 > 编程语言> > python下载无法解析webp图片问题

python下载无法解析webp图片问题

作者:互联网

问题描述

使用 python 下载 webp 图片,使用 PIL 打开图片报错

img_url = "https://static.dingxiang-inc.com/picture/dx/8WLWdp6Qpc/sem2lub/2700236964d04994b50999a863cbd8e3.webp"
response = requests.get(url=img_url, stream=True)
byte_stream = BytesIO(response.content)
img = Image.open(byte_stream) # 报错
img.show()

报错内容:

OSError: cannot identify image file

问题原因

是因为PIL版本的问题,卸载之后重装 PIL

解决方法

重装下面版本的 PIL ,命令如下:

pip install Pillow==9.0.1

安装后问题解决。

标签:PIL,stream,img,python,url,webp,报错,解析
来源: https://blog.csdn.net/Dxy1239310216/article/details/123052390