python中的HttpError都是IOError的子类吗
在我们的代码中,我们捕获 IOError 并在重新引发之前将其记录下来。我收到“对等方重置连接”,但日志中没有任何内容。 python中的“连接由peer重置”是IOError的子类吗?
.....
File "/usr/lib/python2.5/httplib.py", line 1047, in readline
s = self._read()
File "/usr/lib/python2.5/httplib.py", line 1003, in _read
buf = self._ssl.read(self._bufsize)
error: (104, 'Connection reset by peer')
In our code we catch IOError and log it before reraising. I am getting a "connection reset by peer", but nothing in the logs. Is "connection reset by peer" a subclass of IOError in python?
.....
File "/usr/lib/python2.5/httplib.py", line 1047, in readline
s = self._read()
File "/usr/lib/python2.5/httplib.py", line 1003, in _read
buf = self._ssl.read(self._bufsize)
error: (104, 'Connection reset by peer')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您粘贴的堆栈跟踪看起来像类
error
的一些异常,带有参数(104, 'Connection Reset by Peer
)。所以看起来它根本不是 HTTPError 异常。在我看来,它实际上是一个 socket.error。从 Python 2.6 开始,这个类确实是 IOError 的子类。
但我想这不是你的问题,因为你问的是 HttpError 异常。您能否重新表述您的问题以澄清您的假设和期望?
来自 usawaretech 的评论:
我猜它是一个 socket.error 因为我使用了标准库的 索引文档,并且因为我之前遇到过这个错误。
您使用什么版本的 Python?我猜它是Python 2.5或更早版本。
如果您的目的是记录并重新引发异常,那么最好使用裸异常:
此外,您还可以使用
exception.__module__
找到定义异常类的模块。The stack trace you pasted looks like some Exception of class
error
with arguments(104, 'Connection reset by peer
).So it looks like it's not a HTTPError exception at all. It looks to me like it's actually a socket.error. This class is indeed a subclass of IOError since Python 2.6.
But I guess that's not your question, since you are asking about HttpError exceptions. Can you rephrase your question to clarify your assumptions and expectations?
Comment from usawaretech:
I guess it is a socket.error because I used the index of the standard library documentation, and because I encountered this error before.
What version of Python are you using? I guess it's Python 2.5 or earlier.
If your intent is to log and re-raise exceptions, it would be a better idea to use a bare except:
Also, you can find the module where the exception class was defined using
exception.__module__
.