Anoop R
Anoop R

Reputation: 555

Connection to Hbase using python is failing

I am trying to connect to Hbase using python sample code used

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

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

which is giving error as follows

print(connection.tables()) Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/happybase/connection.py", line 242, in tables names = self.client.getTableNames() File "/usr/local/lib/python2.7/dist-packages/thriftpy/thrift.py", line 198, in _req return self._recv(_api) File "/usr/local/lib/python2.7/dist-packages/thriftpy/thrift.py", line 210, in _recv fname, mtype, rseqid = self._iprot.read_message_begin() File "thriftpy/protocol/cybin/cybin.pyx", line 439, in cybin.TCyBinaryProtocol.read_message_begin (thriftpy/protocol/cybin/cybin.c:6470) cybin.ProtocolError: No protocol version header

OS : Ubuntu 16.04 I am using python 2.7 Hbase Version 1.1 Help me to understand the issue.Is there any better way to connect to Hbase other than happybase

Thanks

Upvotes: 4

Views: 5604

Answers (3)

minglyu
minglyu

Reputation: 3337

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

here port is the thrift server port, by default, the value is 9090. If you are using docker, you should export the port 9090 from host to your docker container.

exec into your container, and start the thrift server:

/opt/hbase-1.2.5/hbase thrift2 start

2024-02-02 09:11:25,080 INFO  [main] http.HttpServer: Jetty bound to port 9095
2024-02-02 09:11:25,080 INFO  [main] mortbay.log: jetty-6.1.26
2024-02-02 09:11:26,630 INFO  [main] mortbay.log: Started [email protected]:9095
2024-02-02 09:11:26,644 INFO  [main] thrift2.ThriftServer: starting HBase ThreadPool Thrift server on 0.0.0.0/0.0.0.0:9090

Upvotes: 0

Amod
Amod

Reputation: 676

Thanks for asking the question, I did fall into the same issue, where there is no answer on the internet. Not sure are we the only one hitting to this or not.

But here is how I figured out to fix the issue, from the error its clear that its something to do with thrift, so check the following

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

if thrift is not running! you may need to start thrift

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

then try your code.

import happybase

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

Auto Connection to hbase

import happybase

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

As an alternative you an use starbase but its no longer active i belive for this you need to start rest API. /usr/hdp/current/hbase-master/bin/hbase-daemon.sh start rest -p 8000 --inforport 8001 Try the happybase and let us know if you are hitting to same issue.

BTW my testing was done on HDP2.5

Further reference: https://github.com/wbolster/happybase/issues/161

which i dont recommend unless you know what you are doing

remove the following property: from 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>

Hope this helps,
Amod

Upvotes: 6

void
void

Reputation: 2533

Either you do autoconnect = True or you start it explicitly using connection.open(). You don't have to do both together.

Upvotes: 0

Related Questions