catch specific HTTP error in python -
i want catch specific http error , not 1 of entire family.. trying --
import urllib2 try: urllib2.urlopen("some url") except urllib2.httperror: <whatever>
but end catching kind of http error, want catch if specified webpage doesn't exist!! that's http error 404..but don't know how specify catch error 404 , let system run default handler other events..ny suggestions??
just catch urllib2.httperror
, handle it, , if it's not error 404, use raise
re-raise exception.
see python tutorial.
so do:
import urllib2 try: urllib2.urlopen("some url") except urllib2.httperror err: if err.code == 404: <whatever> else: raise
Comments
Post a Comment