Using the Python requests library, I wanted to make a PUT request, and ignore any ConnectionError if it was an error 104 “Connection reset by peer”. (104 is ECONNRESET defined in errno.h). If this error was raised, the traceback I received was as follows:
Using dir(requests.ConnectionError) showed that it had an errno attribute, and so I naïvely tried this solution first:
This did not work. The exception was always raised.
It turned out that err.errno was None. (This appears to be because err.errno actually comes from IOError, the standard Python class from which ConnectionError inherits).
Tenacious use of dir revealed that the correct rune is not err.errno, but err.args[0].args[1].errno. This process of discovery can be seen in the log below: