我正在使用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")
此方法或以下方法均不适用于我:
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")
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
答案 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")