开发者

python httplib httpexception error codes

Does httplib.HTTPExcepti开发者_JAVA百科on have error codes? If so how do I get at them from the exception instance? Any help is appreciated.


The httplib module doesn't use exceptions to convey HTTP responses, just genuine errors (invalid HTTP responses, broken headers, invalid status codes, prematurely broken connections, etc.) Most of the httplib.HTTPException subclasses just have an associated message string (stored in the args attribute), if even that. httplib.HTTPException itself may have an "errno" value as the first entry in args (when raised through httplib.FakeSocket) but it's not a HTTP error code.

The HTTP response codes are conveyed through the httplib.HTTPConnection object, though; the getresponse method will (usually) return a HTTPResponse instance with a status attribute set to the HTTP response code, and a reason attribute set to the text version of it. This includes error codes like 404 and 500. I say "usually" because you (or a library you use) can override httplib.HTTPConnection.response_class to return something else.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜