2

I'm using happybase to connect to HBase. So far the connection is fine. We have thrift up and running. I'm able to connect to the table (AFAIK), but when I try to scan the table I get TTransportException: TSocket read 0 bytes. Here is the code that I am using.

import happybase
import json

connection = happybase.Connection('ipaddress', '22')

table = connection.table('rawdataingestion')

for key, data in table.scan():
    print key, data
    break

I'm using break here so it doesn't print out a google rows. I just want to see that it's making a connection and bringing in the data.

Here's the error.

---> 38 for key, data in table.scan():
     39     print key, data
     40     break

/root/anaconda/lib/python2.7/site-packages/happybase/table.pyc in scan(self, row_start, row_stop, row_prefix, columns, filter, timestamp, include_timestamp, batch_size, scan_batching, limit, sorted_columns)
    372             )
    373             scan_id = self.connection.client.scannerOpenWithScan(
--> 374                 self.name, scan, {})
    375 
    376         logger.debug("Opened scanner (id=%d) on '%s'", scan_id, self.name)

/root/anaconda/lib/python2.7/site-packages/happybase/hbase/Hbase.pyc in scannerOpenWithScan(self, tableName, scan, attributes)
   1917     """
   1918     self.send_scannerOpenWithScan(tableName, scan, attributes)
-> 1919     return self.recv_scannerOpenWithScan()
   1920 
   1921   def send_scannerOpenWithScan(self, tableName, scan, attributes):

/root/anaconda/lib/python2.7/site-packages/happybase/hbase/Hbase.pyc in recv_scannerOpenWithScan(self)
   1930 
   1931   def recv_scannerOpenWithScan(self, ):
-> 1932     (fname, mtype, rseqid) = self._iprot.readMessageBegin()
   1933     if mtype == TMessageType.EXCEPTION:
   1934       x = TApplicationException()

/root/anaconda/lib/python2.7/site-packages/thrift/protocol/TBinaryProtocol.pyc in readMessageBegin(self)
    138         raise TProtocolException(type=TProtocolException.BAD_VERSION,
    139                                  message='No protocol version header')
--> 140       name = self.trans.readAll(sz)
    141       type = self.readByte()
    142       seqid = self.readI32()

/root/anaconda/lib/python2.7/site-packages/thrift/transport/TTransport.pyc in readAll(self, sz)
     56     have = 0
     57     while (have < sz):
---> 58       chunk = self.read(sz - have)
     59       have += len(chunk)
     60       buff += chunk

/root/anaconda/lib/python2.7/site-packages/thrift/transport/TTransport.pyc in read(self, sz)
    157       return ret
    158 
--> 159     self.__rbuf = StringIO(self.__trans.read(max(sz, self.__rbuf_size)))
    160     return self.__rbuf.read(sz)
    161 

/root/anaconda/lib/python2.7/site-packages/thrift/transport/TSocket.pyc in read(self, sz)
    118     if len(buff) == 0:
    119       raise TTransportException(type=TTransportException.END_OF_FILE,
--> 120                                 message='TSocket read 0 bytes')
    121     return buff
    122 

TTransportException: TSocket read 0 bytes
Ravaal
  • 3,233
  • 6
  • 39
  • 66

1 Answers1

2

The problem was here-

connection = happybase.Connection('ipaddress', '22')

The default port for thrift is 9090. I changed the code to

connection = happybase.Connection('ipaddress', 9090) 

and got my data.

Desprit
  • 707
  • 2
  • 11
  • 24
Ravaal
  • 3,233
  • 6
  • 39
  • 66