You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Colab使用HappyBase操作HBase读取正常写入失败问题求助

HappyBase写入HBase报错修复方案

报错根因

  • TTransportException: TSocket read 0 bytes:服务启动顺序错误,Thrift服务启动早于HBase Master,导致Thrift未成功关联HBase集群,写入请求触发断连。
  • TypeError: __str__ returned non-string (type bytes):HBase列标识格式不符合要求,列族和列限定符需要用:分隔,即使列限定符为空也不能省略冒号,同时可能存在Thrift协议版本不兼容问题。

修复步骤

1. 修正服务启动顺序与配置

替换原有服务启动代码,先启动HBase集群再启动Thrift服务,同时指定兼容的传输协议与格式:

!stop-hbase.sh
!pip install happybase
import happybase
# 优先启动HBase集群
!start-hbase.sh
# 启动Thrift时指定协议参数避免兼容问题
!hbase-daemon.sh start thrift -f compact -t binary
!jps

确认返回结果中HMaster、ThriftServer进程均正常运行即可。

2. 修正连接与写入语法

连接时指定协议匹配参数,写入时列标识补全冒号:

# 连接时新增协议参数
connection = happybase.Connection('localhost',9090, transport='buffered', protocol='binary')
myCars = connection.table('cars2')
# 列标识格式为 列族:列限定符,空限定符也要保留冒号
myCars.put(b'Hindustan',{b'make:': b'Ambassador', b'model:': b'1963'})

3. 验证写入结果

执行以下命令确认数据写入成功:

print(myCars.row(b'Hindustan'))

内容的提问来源于stack exchange,提问作者Calcutta

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 10:54:03