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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM