I work with urllib and urllib2 in python and use them to extract images from urls.
Using something similar to:
try:
buffer = urllib2.url_open (urllib2.Request (url))
f.write (buffer)
f.close
except (Errors that could occur): #Network Errors (?)
print "Failed to retrieve" + url
pass
Now it often happens that the image does not load / does not work when using the site through a regular web browser, this is apparently due to the high load on the server or because the image does not exist or cannot be restored by the server.
Whatever the reason, the image does not load, and a similar situation may also arise when using the script. Since I don’t know what mistake he can cause, how can I do this?
I think that mentioning all possible errors in the urllib2 library, urllib in the except statement may be redundant, so I need a better way.
(I may also have / will have to handle a broken Wi-Fi, an unavailable server, etc., which means more errors)
source
share