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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -