【发布时间】:2013-09-01 17:28:38
【问题描述】:
我正在尝试从 url 访问图像:
http://www.lifeasastrawberry.com/wp-content/uploads/2013/04/IMG_1191-1024x682.jpg
但是,它在最后一步失败并显示 IOError("cannot identify image file")。不知道发生了什么或如何解决它。它已与许多其他 url 图片一起使用。
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
opener.addheaders = [('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')]
opener.addheaders = [('Accept-Encoding', 'gzip,deflate,sdch')]
response = opener.open(image_url,None,5)
img_file = cStringIO.StringIO(response.read())
image = Image.open(img_file)
这个网址也失败了:
http://www.canadianliving.com/img/photos/biz/Greek-Yogurt-Ceaser-Salad-Dressi1365783448.jpg
【问题讨论】:
-
如果我不将标题添加到
opener,它对我有用。
标签: python http encoding gzip python-imaging-library