【问题标题】:Can't use 'put'() to add data to hbase with happybase不能使用 'put'() 通过happybase 向 hbase 添加数据
【发布时间】:2020-05-19 16:21:51
【问题描述】:

我的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里的一切都OK了,搞不明白哪里出了问题,快崩溃了。

【问题讨论】:

  • 对了,我在master主机上运行这个文件,需要设置什么吗?

标签: hadoop hbase python-3.7 happybase


【解决方案1】:

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

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

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

希望对你有帮助。

【讨论】:

  • 感谢您的评论,尽管我的代码已用md5(item['title'].encode('utf-8')).hexdigest() 修复。这是一个奇怪的问题,我尝试使用encode()but 它。只是不像上面那样工作,encode()hexdigest() 之间可能有些不同。无论如何,非常感谢!
猜你喜欢
  • 2017-12-12
  • 1970-01-01
  • 2017-10-23
  • 1970-01-01
  • 1970-01-01
  • 2017-07-28
  • 1970-01-01
  • 2021-02-08
  • 2018-08-19
相关资源
最近更新 更多