• happybase(TSocket read 0 bytes)


    关于报错
    happybase 是使用python连接hbase的一个第三方库,目前基于thrift1 。在使用过程中经常碰到报错

    TTransportException(type=4, message='TSocket read 0 bytes')

    即使使用thrift server首页上提供了连接Apache HBase Wiki on Thrift里的demo也一样报错。

    测试代码
    import happybase
    def get_tables_name(host,port):
    conn = happybase.Connection(host=host,port=port)
    return conn.tables()
    很简单,就是连接hbase,返回所有table名称。

    报错可能原因
    hbase 未开启thrift服务
    Connection参数与thrift服务不匹配
    Connection参数
    看一下官网wiki上建立连接的例子

    from thrift.transport.TSocket import TSocket
    from thrift.transport.TTransport import TBufferedTransport
    from thrift.protocol import TBinaryProtocol
    from hbase import Hbase

    transport = TBufferedTransport(TSocket(host, port))
    transport.open()
    protocol = TBinaryProtocol.TBinaryProtocol(transport)

    client = Hbase.Client(protocol)

    构建一个连接需要两个辅助类 TBufferedTransport,TBinaryProtocol。其中transport负责通讯协议,protocol负责序列化协议。

    happybase connection
    happybase官网上对于connection的介绍connection的介绍

    总结有三个参数需要匹配

    protocol: binary (the default) and compact
    compat :0.90, 0.92, 0.94, or 0.96 (the default)
    transport :buffered (the default) and framed
    在我将上述测试代码改为

    import happybase
    def get_tables_name(host,port):
    conn = happybase.Connection(host=host,port=port,protocol='compact',transport='framed')
    return conn.tables()
    就没问题了。
    转自:https://blog.csdn.net/zhnxin_163/article/details/82879417

  • 相关阅读:
    glib文档
    2020第42周面向失败设计
    2020第41周中年危机焦虑
    2020第40周选合适的工具
    2020第39周微行动思维
    2020第38周
    2020第37周
    2020第36周
    2020第35周不要让孩子输在起跑线
    2020第34周滥竽充数
  • 原文地址:https://www.cnblogs.com/lyy-blog/p/10178486.html
Copyright © 2020-2023  润新知