关于报错
happybase 是使用python链接hbase的一个第三方库,目前基于thrift1 。在使用过程当中常常碰到报错html
TTransportException(type=4, message='TSocket read 0 bytes')python
即便使用thrift server首页上提供了链接Apache HBase Wiki on Thrift里的demo也同样报错。api
测试代码
import happybase
def get_tables_name(host,port):
conn = happybase.Connection(host=host,port=port)
return conn.tables()
很简单,就是链接hbase,返回全部table名称。app
报错可能缘由
hbase 未开启thrift服务
Connection参数与thrift服务不匹配
Connection参数
看一下官网wiki上创建链接的例子测试
from thrift.transport.TSocket import TSocket
from thrift.transport.TTransport import TBufferedTransport
from thrift.protocol import TBinaryProtocol
from hbase import Hbase.net
transport = TBufferedTransport(TSocket(host, port))
transport.open()
protocol = TBinaryProtocol.TBinaryProtocol(transport)server
client = Hbase.Client(protocol)htm
构建一个链接须要两个辅助类 TBufferedTransport,TBinaryProtocol。其中transport负责通信协议,protocol负责序列化协议。blog
happybase connection
happybase官网上对于connection的介绍connection的介绍get
总结有三个参数须要匹配
protocol: binary (the default) and compact
compat :0.90, 0.92, 0.94, or 0.96 (the default)
transport :buffered (the default) and framed
在我将上述测试代码改成
import happybasedef get_tables_name(host,port): conn = happybase.Connection(host=host,port=port,protocol='compact',transport='framed') return conn.tables()就没问题了。转自:https://blog.csdn.net/zhnxin_163/article/details/82879417