happybase 连接 hbase 报错问题

tech2022-11-26  90

happybase 连接 hbase 报错问题

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

错误1

thriftpy2.transport.base.TTransportException: TTransportException(type=1, message="Could not connect to ('xx.xx.xx.xx', 9090)")

此情况说明host地址有误,请检查host地址是否正确

错误2

没有报连接错误,但是无法获取数据:

thriftpy.transport.TTransportException: TTransportException(type=4, message='TSocket read 0 bytes')

如果连接没有问题,但无法获取数据,首先确认hbase thrift 服务是否开启:

使用jps命令,查看thrift服务是否开启:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-W1fsiMz9-1599103330206)(C:\Users\t\AppData\Roaming\Typora\typora-user-images\image-20200903110442872.png)]

如果有ThriftServer 说明服务已经 开启

如果没有开启,使用以下命令开启:

hbase thrift start -p 9090

如果服务已经开启,但依然无法获取数据,此时需要修改happybase客户端的连接参数:

happybase 连接hbase的代码中,transport 参数默认为:‘buffered’,protocol 参数默认为:‘binary’, 如果这些参数与hbase服务器配置不同,则同样无法获取数据。

将代码参数修改为如下样式:

import happybase conn = happybase.Connection(host='localhost',port=9090,transport='framed',protocol='compact') print(conn.tables())

protocol=‘compact’) print(conn.tables())

至此,便可以通过happybase连接hbase了。
最新回复(0)