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

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

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744278754a4566465.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信