We are already importing urlib2, so you might just want to use urllib2.HTTPError in the code.