【问题标题】:Why does happybase return "TSocket read 0 bytes" when I try running table.scan()?为什么当我尝试运行 table.scan() 时,happybase 返回“TSocket read 0 bytes”?
【发布时间】:2016-01-11 16:57:07
【问题描述】:

我正在使用 happybase 连接到 HBase。到目前为止,连接良好。我们已经开始节俭了。我能够连接到表(AFAIK),但是当我尝试扫描表时,我得到TTransportException: TSocket read 0 bytes。这是我正在使用的代码。

import happybase
import json

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

table = connection.table('rawdataingestion')

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

我在这里使用 break,所以它不会打印出 google 行。我只是想看看它正在建立连接并引入数据。

这是错误。

---> 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

【问题讨论】:

    标签: python hbase thrift happybase


    【解决方案1】:

    问题出在这里-

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

    thrift 的默认端口是9090。我将代码更改为

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

    并得到了我的数据。

    【讨论】:

    • 在我看来,这里的端口号必须是整数?
    • 必须是整数,否则会出现“TypeError: an integer is required”
    猜你喜欢
    • 2019-07-06
    • 1970-01-01
    • 1970-01-01
    • 2019-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多