最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - PIL.UnidentifiedImageError for some image URL, but not others - Stack Overflow

programmeradmin4浏览0评论

I'm trying to open an image at a URL using Pillow, but it only works for some URL. In my code below, URL1 works but not URL2.

import requests
from PIL import Image

url1 = "/200"
# url2 = ".jpg"

image = Image.open(requests.get(url, stream=True, verify=False).raw)

If I run the code with URL2, it gives me an error:

PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x...>

I am able to open both URLs with my browser so I'm really curious as to why. Are there any methods that will work on both?

Thanks

发布评论

评论列表(0)

  1. 暂无评论