thrift.transport.TTransport.TTransportException: TSocket read 0 bytes报错解决

一、问题描述

htrift版本:2.0.0-cdh6.0.1
hbase版本:1.2.0-cdh5.7.0

使用 thrift client with python 连接 hbase 报错:

File "C:\Users\HP\env1\lib\site-packages\thrift\transport\TSocket.py", line 132, in read
    message='TSocket read 0 bytes')
thrift.transport.TTransport.TTransportException: TSocket read 0 bytes

二、查找原因
1)hbase连接代码

from thrift.transport import TSocket
from thrift.protocol import TBinaryProtocol
from thrift.transport import TTransport

transport = TTransport.TBufferedTransport(TSocket.TSocket(10.201.7.113, int(port)))
protocol = TBinaryProtocol.TBinaryProtocolAccelerated(self.transport)

2) hbase-site.xml 配置如下

   <property>
      <name>hbase.regionserver.thrift.framed</name>
      <value>true</value>
   </property>
   <property>
      <name>hbase.regionserver.thrift.compact</name>
      <value>true</value>
   </property>

3) thrift server日志如下:(/var/log/hbase/hbase-hbase-thrift-.log)

 INFO  [main] mortbay.log: Started HttpServer$SelectChannelConnectorWithSafeStartup@0.0.0.0:9095
 DEBUG [main] thrift.ThriftServerRunner: Using compact protocol
 DEBUG [main] thrift.ThriftServerRunner: Using framed transport
 INFO  [main] thrift.ThriftServerRunner: starting TBoundedThreadPoolServer on /0.0.0.0:9090; min worker threads=16, max worker threads=1000, max queued requests=1000

由以上可知,是因为thrift 的server端和client端的协议不匹配造成的。

解决方案:
方案一:修改hbase-site.xml,禁用TFramedTransport和TCompactProtocol功能,即:

   <property>
      <name>hbase.regionserver.thrift.framed</name>
     <value>false</value>
   </property>
   <property>
      <name>hbase.regionserver.thrift.compact</name>
      <value>false</value>
   </property>

重启thrift 服务器: service hbase-thrift restart

方案二:修改客户端代码

transport = TFramedTransport(TSocket('192.168.0.10', 9090))  
protocol = TCompactProtocol.TCompactProtocol(transport)  
client = Hbase.Client(protocol)  
transport.open()
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值