从imageio.imread处理HTTPError

时间:2019-03-29 16:55:34

标签: python-3.x python-imageio

我正在使用imageio.imread,并提供了可能会出现404错误的图片网址列表。

import imageio as io
from urllib3.exceptions import HTTPError as BaseHTTPError

try:
   imag = io.imread("http://static.booking.com/images/hotel/org/591/59160587.jpg")
except BaseHTTPError as e:
   print("whatever")

此方法或以下方法均不适用于我:

使用urllib

import imageio as io
from requests.exceptions import HTTPError

try:
   imag = io.imread("http://static.booking.com/images/hotel/org/591/59160587.jpg")
except HTTPError as e:
   print("whatever")

使用requests.exceptions

HTTPError: HTTP Error 404: Not Found

下面的Colab笔记本显示了两者如何给TestBed.configureTestingModule({ declarations: [ MyComponent ] }) .overrideComponent(MyComponent, { set: { changeDetection: ChangeDetectionStrategy.Default } }) .compileComponents(); https://colab.research.google.com/drive/1uOOzJ4jDvYKe5zdFfxDkbcNRpxcjaOOj

1 个答案:

答案 0 :(得分:0)

我用

解决了这个问题
import imageio as io
from urllib import error

try:
   imag = io.imread("http://static.booking.com/images/hotel/org/591/59160587.jpg")
except error.HTTPError as e:
   print("whatever")