0

I'm using imageio.imread and have a list of image URLs that can give 404 errors.

import imageio as io

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

Neither this or the following approaches are working for me:

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

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

The Colab notebook below shows how both give HTTPError: HTTP Error 404: Not Found https://colab.research.google.com/drive/1uOOzJ4jDvYKe5zdFfxDkbcNRpxcjaOOj

andandandand
  • 21,946
  • 60
  • 170
  • 271

1 Answers1

0

I fixed this with

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")
andandandand
  • 21,946
  • 60
  • 170
  • 271