1

I try to connect to HBase and manipulate it through the happybase package of python Here is the code i used to connect to HBase: (the 'print' lines help me to locate where the program is stopped)

import happybase

connection = happybase.Connection('197.12.8.2',2181)
print('0')
connection.open()
print('1')
table = connection.table('customerLocations')
print('2')

table.put('1', {'latitude': '11','longitude': '22'})
print('3')
row = table.row('0')
print('4')
print(row)
print('5')

But when executing the code,i got this an exception (thriftpy.transport.TTransportException) :

0
1
2
Traceback (most recent call last):
  File "test2.py", line 10, in <module>
    table.put('1', {'latitude': '11','longitude': '22'})
  File "/usr/lib/python2.7/site-packages/happybase/table.py", line 464, in put
    batch.put(row, data)
  File "/usr/lib/python2.7/site-packages/happybase/batch.py", line 137, in __exit__
    self.send()
  File "/usr/lib/python2.7/site-packages/happybase/batch.py", line 60, in send
    self._table.connection.client.mutateRows(self._table.name, bms, {})
  File "/usr/lib64/python2.7/site-packages/thriftpy/thrift.py", line 198, in _req
    return self._recv(_api)
  File "/usr/lib64/python2.7/site-packages/thriftpy/thrift.py", line 210, in _recv
    fname, mtype, rseqid = self._iprot.read_message_begin()
  File "thriftpy/protocol/cybin/cybin.pyx", line 429, in cybin.TCyBinaryProtocol.read_message_begin (thriftpy/protocol/cybin/cybin.c:6325)
  File "thriftpy/protocol/cybin/cybin.pyx", line 60, in cybin.read_i32 (thriftpy/protocol/cybin/cybin.c:1546)
  File "thriftpy/transport/buffered/cybuffered.pyx", line 65, in thriftpy.transport.buffered.cybuffered.TCyBufferedTransport.c_read (thriftpy/transport/buffered/cybuffered.c:1881)
  File "thriftpy/transport/buffered/cybuffered.pyx", line 69, in thriftpy.transport.buffered.cybuffered.TCyBufferedTransport.read_trans (thriftpy/transport/buffered/cybuffered.c:1948)
  File "thriftpy/transport/cybase.pyx", line 61, in thriftpy.transport.cybase.TCyBuffer.read_trans (thriftpy/transport/cybase.c:1472)
  File "/usr/lib64/python2.7/site-packages/thriftpy/transport/socket.py", line 125, in read
    message='TSocket read 0 bytes')
thriftpy.transport.TTransportException: TTransportException(message='TSocket read 0 bytes', type=4)

I don't know where the problem comes from ..

I.Scale
  • 35
  • 5

1 Answers1

0

here is the error connection = happybase.Connection('197.12.8.2',2181)

you should connect the thrift server, and the server port is 9090 as default, not 2181, it's the port of zookeeper