When opening a socket via Thrift, the exception message simply says:
"Could not connect to localhost:9160"
The underlying OS error is lost. This is a classic example of the anti-pattern called "exception masquerading". The exception handler loses essential information related to the source of the error. This makes troubleshooting difficult.
The problem lies inside TSocket.py, the original socket.error is simply discarded:
The TTransportException should carry as much information as possible relating to the original error, e.g.:
Could not connect to (localhost:9090): (<class 'socket.error'>, error(111, 'Connection refused'))
The TTransportException should carry the real exception it was trying to hide as a member variable so that the caller can take appropriate action in case of transient failures (e.g. EINTR).