不能使用 'put'() 使用 happybase 向 hbase 添加数据



我的python版本是3.7,运行pip3 install happybase后,我启动了命令hbase thrift start并尝试编写一个简短的.py文件,如下所示:

import happybase
connection = happybase.Connection('master')
table = connection.table('jmlr')   #'jmlr' is a table in hbase
for i in table.scan():
print(i)
table.put('001', {'title':'dasds'})   #error here
connection.close()

当它即将运行table.put()时,它报告了这样的错误:

thriftpy2.transport.base.TTransportException: TTransportException(type=4, message='TSocket read 0 bytes')

同时,thrift报告了一个错误:

ERROR [thrift-worker-1] thrift.TBoundedThreadPoolServer: Error occurred during processing of message. java.lang.IllegalArgumentException: Invalid famAndQf provided.

但是刚才我再次运行了这个python文件,它给了我一个不同的错误thrift

thrift.TBoundedThreadPoolServer: Thrift error occurred during processing of message. org.apache.thrift.protocol.TProtocolException: Bad version in readMessageBegin

我尝试添加protocol='compact', transport='framed'这样的参数,但这不起作用,甚至table.scan()都失败了。hbase shell一切都很好,所以我无法弄清楚出了什么问题,我快崩溃了。

我遇到了同样的问题并找到了这种解决方案。您需要将甚至空的列限定符(":"符号作为列系列和列限定符之间的分隔符(添加到 put(( 方法中:

table.put('001:', {'title':'dasds'}) 

此外,第二次运行脚本后,您会收到不同的错误消息,因为 thrift 服务器已经失败。

我希望它能帮助你。

最新更新