I'm catching and printing Python Requests ConnectionErrors fine with just this:
except requests.exceptions.ConnectionError as e:
logger.warning(str(e.message))
It prints out messages such as:
HTTPSConnectionPool(host='10.100.24.16', port=443): Max retries exceeded with url: /api/datastores/06651841-bbdb-472a-bde2-689d8cb8da19 (Caused by <class 'socket.error'>: [Errno 61] Connection refused)
and
HTTPSConnectionPool(host='10.100.24.16', port=443): Max retries exceeded with url: /api/datastores/06651841-bbdb-472a-bde2-689d8cb8da19 (Caused by <class 'socket.error'>: [Errno 65] No route to host)
And many others. What I'm wondering is, what's the best, most Pythonic, way to get that errno that's displaying in the message? I'd like to have a reliable system for catching the issues and offering as helpful and relevant error message to the user as possible. As far as I can tell, ConnectionError is an indirect decedent of BaseException, with no new properties or methods being added beyond what BaseException offers. I'm hesitant to simply use regex because it seems to me I run the risk of assuming all error messages are formatted the same way in all localities.