Python error codes httplib httpexception
The module httplib
does not use exceptions to pass HTTP responses, just real errors (bad HTTP responses, broken headers, invalid status codes, prematurely broken connections, etc.). Most subclasses of httplib.HTTPException have an associated message string (stored in an attribute args
), if not even that. httplib.HTTPException
itself may have the value "errno" as the first entry in args
(when brought up via httplib.FakeSocket), but this is not an HTTP error code.
HTTP response codes are passed through the object httplib.HTTPConnection
; the method getresponse
will (usually) return an instance HTTPResponse
with the attribute status
set to the HTTP response code and the attribute reason
set to its text version. This includes error codes such as 404
and 500
. I say "usually" because you (or the library you are using) can override httplib.HTTPConnection.response_class
to return something else.
a source to share