python通过thrift访问HBase报错Invalid method name

出现的问题

在准备用python的happybase包通过thrift连接HBase,运行脚本的时候报错,报错大体如下:

thrift.Thrift.TApplicationException: Invalid method name:'getTableNames'

代码如下:

# -*- coding: utf-8 -*-
import happybase

def demo_hbase():
    #创建一个连接
    conn = happybase.Connection("192.168.1.10")
    #获取所有的表
    tbs = conn.tables();
    #打印所有表
    print (tbs)

if __name__=="__main__":
    demo_hbase()

产生的原因

后来通过查询资料,怀疑是客户端thrift版本和hbase thrift server的thrift版本不一致造成的。

果然thrift server上是使用的thrift2启动的,而客户端使用的是thrift访问的。

#启动命令
hbase-daemon.sh start thrift2

解决方法

因为根本原因在于客户端和服务器thrift版本不一致,那么解决方法有两个:

1、服务端以启动thrift版本的thrift server

hbase 的 thrift server以thrift1方式启动。

#
hbase-daemon.sh stop thrift2
#启动命令
hbase-daemon.sh start thrift

如果想使用happybase这个好用的模块去连接hbase,只能使用thrift,因为happybase目前还不支持thrift2。

2、客户端以thrift2的方式请求

可以参考:https://blog.csdn.net/lesorb/article/details/47658575

Thrift和Thrift2比较

参考:https://blog.csdn.net/guxch/article/details/12163047

发布了74 篇原创文章 · 获赞 74 · 访问量 5万+

猜你喜欢

转载自blog.csdn.net/chybin500/article/details/80498516