使用python连接到Hbase失败

问题描述 投票:3回答:2

我正在尝试使用使用的python示例代码连接到Hbase

import happybase
connection = happybase.Connection(myhost,port, autoconnect=True)

# before first use:
connection.open()
print(connection.tables())

这给出了如下错误

print(connection.tables())Traceback(最近一次调用last):文件“”,第1行,在文件“/usr/local/lib/python2.7/dist-packages/happybase/connection.py”,第242行,在表names = self.client.getTableNames()文件“/usr/local/lib/python2.7/dist-packages/thriftpy/thrift.py”,第198行,在_req中返回self._recv(_api)文件“ /usr/local/lib/python2.7/dist-packages/thriftpy/thrift.py“,第210行,在_recv fname,mtype,rseqid = self._iprot.read_message_begin()文件”thriftpy / protocol / cybin / cybin。 pyx“,第439行,在cybin.TCyBinaryProtocol.read_message_begin(thriftpy / protocol / cybin / cybin.c:6470)cybin.ProtocolError:无协议版本标题

操作系统:Ubuntu 16.04我使用的是python 2.7 Hbase版本1.1帮助我理解这个问题。除了happybase之外还有更好的方法可以连接到Hbase

谢谢

python hadoop hbase happybase
2个回答
1
投票

感谢您提出这个问题,我确实陷入了同样的问题,互联网上没有答案。不确定我们是否是唯一一个打到这个与否的人。

但这里是我如何找出解决问题的方法,从错误中明确表示与thrift有关,所以请检查以下内容

/usr/hdp/current/hbase-master/bin/hbase-daemon.sh start thrift

如果节俭没有运行!你可能需要开始节俭

/usr/hdp/current/hbase-master/bin/hbase-daemon.sh start thrift -p 9090 --infoport 9091

然后尝试你的代码。

import happybase

c = happybase.Connection('127.0.0.1',9090, autoconnect=False)
c.open()
print(c.tables())

自动连接到hbase

import happybase

c = happybase.Connection('127.0.0.1',9090)
print(c.tables())

作为替代方案,你可以使用starbase但它不再活跃我相信你需要启动rest API。 /usr/hdp/current/hbase-master/bin/hbase-daemon.sh start rest -p 8000 --inforport 8001尝试使用happybase并告诉我们您是否遇到同样的问题。

顺便说一句,我的测试是在HDP2.5上完成的

进一步参考:https://github.com/wbolster/happybase/issues/161

除非你知道你在做什么,否则我不推荐

从hbase-site.xml [/etc/hbase/conf/hbase-site.xml]中删除以下属性:

<property>
  <name>hbase.regionserver.thrift.http</name>
  <value>true</value>
</property>
<property>
  <name>hbase.thrift.support.proxyuser</name>
  <value>true/value>
</property>

希望这可以帮助, 阿莫德


0
投票

要么你做autoconnect = True,要么你使用connection.open()明确地开始。你不必一起做两件事。

© www.soinside.com 2019 - 2024. All rights reserved.