我正在尝试在 Windows 上的 Eclise RSE 的远程机器(Ubuntu)上使用 Hbase、thrift 和 python。一切正常,但是当我尝试连接到 localhost 时出现错误:
thrift.transport.TTransport.TTransportException: Could not connect to localhost:9090
如果我通过远程机器上的 ssh 终端运行此代码,它会完美运行。
这是我的代码:
#!/usr/bin/env python
import sys, glob
sys.path.append('gen-py')
sys.path.insert(0, glob.glob('lib/py/build/lib.*')[0])
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from hbase import Hbase
# Connect to HBase Thrift server
transport = TTransport.TBufferedTransport(TSocket.TSocket('localhost', 9090))
protocol = TBinaryProtocol.TBinaryProtocolAccelerated(transport)
# Create and open the client connection
client = Hbase.Client(protocol)
transport.open()
tables = client.getTableNames()
print(tables)
# Do Something
transport.close()