python-3.x - 处理来自 imageio.imread 的 HTTPError
问题描述
我正在使用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
解决方案
我用
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")
推荐阅读
- azure - 是否可以映射/重命名从 Azure 应用配置加载的键?
- python - 熊猫`at`与列表`append`
- wpf - 如何在 WPF 中的所有窗口上应用所有字体设置?
- powershell - Rename-Item 失败并显示“无法重命名,因为 'C:\Folder\ Example App Folder 中的项目”不存在
- python - 解封数据框会导致 TypeError
- google-apps-script - 通过 Google 表格中的单元格内容控制文本大小
- javascript - 2个javascript语句的范围问题
- python - Pandas groupby、bin 和 average
- pyspark - 将字符串(带时间戳)转换为 pyspark 中的时间戳
- python - 如何获取 set_index 第一个值