Question

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')
Was it helpful?

Solution

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:

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

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:

try:
    risky_code()
except:
    logger.debug(...)
    raise

Also, you can find the module where the exception class was defined using exception.__module__.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top