THRIFT-792: Preserve last connect exception

Preserves the last exception when TSocket connect fails to provide more
context to callers. The exceptions are already logged at info level, but
callers may suppress that or want to view details in the exception, so
attach the last as an inner layer of TTransportException, similar to
gaierror above.
diff --git a/lib/py/test/test_socket.py b/lib/py/test/test_socket.py
index 727aceb..af09515 100644
--- a/lib/py/test/test_socket.py
+++ b/lib/py/test/test_socket.py
@@ -30,6 +30,16 @@
 
 
 class TSocketTest(unittest.TestCase):
+    def test_failed_connection_raises_exception(self):
+        sock = TSocket(host="localhost", port=60606) # unused port
+        with self.assertRaises(TTransportException) as ctx:
+            sock.open()
+        exc = ctx.exception
+        self.assertEqual(exc.type, TTransportException.NOT_OPEN)
+        self.assertIn("Could not connect to any of", exc.message)
+        self.assertIsNotNone(exc.inner)
+        self.assertIn("Connection refused", str(exc.inner))
+
     def test_socket_readtimeout_exception(self):
         acc = ServerAcceptor(TServerSocket(port=0))
         acc.start()