0

我正在使用imageio.imread并且有一个可以给出 404 错误的图像 URL 列表。

import imageio as io

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

这种或以下方法都不适合我:

使用 urllib

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")

使用 requests.exceptions

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")

下面的 Colab 笔记本显示了两者如何给出HTTPError: HTTP Error 404: Not Found https://colab.research.google.com/drive/1uOOzJ4jDvYKe5zdFfxDkbcNRpxcjaOOj

4

1 回答 1

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")
于 2019-03-29T17:42:10.660 回答