Reputation: 1
i am trying to catch warnings and (non-fatal) errors thrown by system packages to implement work-arounds in my code. specifically, i am generating a large amount (thousands) of Cartopy Earth visualizations that require the download of several Goggle Tiles, e.g.,
import cartopy.io.img_tiles as cimgt
thisURL = 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}.jpg'
tileImage = cimgt.GoogleTiles(url=thisURL)
axis.add_image ( tileImage, 2, cmap='gray' )
where "axis" is the figure axis and "2" refers to the level of ArcGIS image detail. if the URL can't be accessed, add_image issues a non-fatal error message
"<urlopen error [Errno 8] nodename nor servname provided, or not known>"
and an image file is generated with the area of that tile left blank. this happens randomly, depending on download traffic at the image server, and forces me to manually post-process any affected images.
i want to catch the error and implement a work-around where i am calling add_image. for that i need to capture the error from add_image into an object that i can test. how can i do that without delving into and modifying system packages?
i added
warnings.filterwarnings("error")
to this function and placed the code with a try/except block, but the error message issued by by add_image does not seem to trigger an exception in my calling function.
Upvotes: 0
Views: 36