thriftpy2.transport.TTransportException: TTransportException("Could not connect to(9090)问题解决

pycharm/python 使用 HappyBase操作Hbase

1 连接Hbase出现的错误信息如下:

thriftpy2.transport.TTransportException: TTransportException(type=1, message=“Could not connect to (‘localhost’, 9090)”)

import happybase
connection = happybase.Connection(host='localhost')
print(connection.tables())

错误信息

Traceback (most recent call last):
  File "/Users/linhaiyan/.workspace/ai/lib/python3.6/site-packages/thriftpy2/transport/socket.py", line 96, in open
    self.sock.connect(addr)
ConnectionRefusedError: [Errno 61] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "localhost", line 3, in 
    connection = happybase.Connection(host='localhost')
  File "/Users/ai/lib/python3.6/site-packages/happybase/connection.py", line 148, in __init__
    self.open()
  File "/Users/.workspace/ai/lib/python3.6/site-packages/happybase/connection.py", line 176, in open
    self.transport.open()
  File "thriftpy2/transport/buffered/cybuffered.pyx", line 34, in thriftpy2.transport.buffered.cybuffered.TCyBufferedTransport.open
  File "/Users/ai/lib/python3.6/site-packages/thriftpy2/transport/socket.py", line 105, in open
    message="Could not connect to %s" % str(addr))
thriftpy2.transport.TTransportException: TTransportException(type=1, message="Could not connect to ('localhost', 9090)")

2 原因分析:

因为Hbase是用Java写的,原生地提供了Java接口,对非Java程序员,如果用的是其他的语言,则需要开启连接原生地提供的thrift接口服务器。

3 解决办法:

1,jps查看进程:

[root@hadoop-master ~]# jps
4320 HMaster
3073 DataNode
2676 NameNode
3572 SecondaryNameNode
11220 Main
4213 HQuorumPeer
4746 HRegionServer
12542 Jps

2,开启ThriftServer服务命令如下:hbase thrift start-port:9090

[root@hadoop-master bin]# hbase thrift start-port:9090

3,再次查看进程:(ThriftServer进程已开启)

[root@hadoop-master ~]# jps
4320 HMaster
3073 DataNode
2676 NameNode
3572 SecondaryNameNode
11220 Main
12404 ThriftServer
4213 HQuorumPeer
4746 HRegionServer
12506 Jps

再次运行python文件

import happybase
connection = happybase.Connection(host='localhost')
print(connection.tables())

输出结果:(没有报错,完美)

[b'student', b'test:user', b'user']

你可能感兴趣的:(hbase)