1

This is how my class looks like:

class ExtHTTPErrorProcessor (urllib2.BaseHandler):

def http_error_default(self, req, fp, code, msg, hdrs):
    print code
    return res
...
...
opener = urllib2.build_opener(ExtHTTPErrorProcessor())
urllib2.install_opener(opener)
urllib2.urlopen(request, data)

All it does is to handle all error code. I follow exactly format from the documentation: http://docs.python.org/library/urllib2.html#urllib2.BaseHandler.http_error_default When error code 400 comes in, it does not call my http_error_default at all, it is calling the one inside urllib2. File "/usr/local/lib/python2.7/urllib2.py", line 521, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) urllib2.HTTPError: HTTP Error 400: Bad Request

I tried adding the method http_error_400, then this method will be called, but I really need the http_error_default. I really need a default one.

Amber
  • 507,862
  • 82
  • 626
  • 550
user926958
  • 9,355
  • 7
  • 28
  • 33

1 Answers1

1

According to this vague old thread you must specify explicit handlers in the "Fancy" URL Opener... I'm sticking with my simple working solution. Just add a try ... except block.

Community
  • 1
  • 1
Cees Timmerman
  • 17,623
  • 11
  • 91
  • 124