[Python-Dev] HTTP responses and errors

Facundo Batista facundo at taniquetil.com.ar
Sun Mar 25 22:45:37 CEST 2007


urllib2.py, after receiving an HTTP response, decides if it was an error
and raises an Exception, or it just returns the info.

For example, you make ``urllib2.urlopen("http://www.google.com")``. If
you receive 200, it's ok; if you receive 500, you get an exception
raised.

How it decides? Function HTTPErrorProcessor, line 490, actually says:

  class HTTPErrorProcessor(BaseHandler):
      ...
      if code not in (200, 206):
          # it prepares an error response 
          ...

Why only 200 and 206? A coworker of mine found this (he was receiving
202, "Accepted").

In RFC 2616 (http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html) it
says about codes "2xx"...

  This class of status code indicates that the client's request was
  successfully received, understood, and accepted.

I know it's no difficult to work this around (you have to catch all the
exceptions, and check for the code), but I was wondering the reasoning
of this.

IMHO, "2xx" should not raise an exception. If you also think it's a bug,
I can fix it.

Regards,

-- 
.   Facundo
.
Blog: http://www.taniquetil.com.ar/plog/
PyAr: http://www.python.org/ar/




More information about the Python-Dev mailing list