在我们的代码中,我们捕获 IOError 并在重新引发之前将其记录下来。我收到“对等方重置连接”,但日志中没有任何内容。 python 中的“连接由对等方重置”是 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')
最佳答案
您粘贴的堆栈跟踪看起来像带有参数(104,'连接由对等方重置
)的类error
的异常。
所以看起来它根本不是 HTTPError 异常。在我看来,它实际上是一个 socket.error 。从 Python 2.6 开始,这个类确实是 IOError 的子类。
但我想这不是你的问题,因为你问的是 HttpError 异常。您能否重新表述您的问题以澄清您的假设和期望?
来自 usawaretech 的评论:
How are you finding out it is a socket error? MY code is something like: try:risky_code(); except IOError: logger.debug('...'); raise; As I am assuming that HttpError is a subclass of IOError, when I get that exception, I am assuming that it be logged. There is nothing in my logs
我猜这是一个socket.error,因为我使用了index of the standard library documentation ,而且因为我以前遇到过这个错误。
您使用的是哪个版本的 Python?我猜它是 Python 2.5 或更早版本。
如果您的目的是记录并重新引发异常,那么最好使用裸异常:
try:
risky_code()
except:
logger.debug(...)
raise
此外,您还可以使用 exception.__module__
找到定义异常类的模块。
关于python - python中的HttpError都是IOError的子类吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1696195/