Hbase thrift2 python客户端API无效
我正在编写一个python脚本来从hbase加载数据。但是Hbase thrift2 python客户端API无效,python,hbase,thrift,Python,Hbase,Thrift,我正在编写一个python脚本来从hbase加载数据。但是节俭生成的文件似乎出了问题。这是我的密码: def create_hbase_connection(): thrift_socket = TSocket.TSocket(thrift_server, thrift_port) thrift_socket.setTimeout(thrift_timeout) thrift_transport = TTransport.TFramedTransport(thrift_s
节俭
生成的文件似乎出了问题。这是我的密码:
def create_hbase_connection():
thrift_socket = TSocket.TSocket(thrift_server, thrift_port)
thrift_socket.setTimeout(thrift_timeout)
thrift_transport = TTransport.TFramedTransport(thrift_socket)
thrift_protocol = TBinaryProtocol.TBinaryProtocolAccelerated(thrift_transport)
thrift_client = THBaseService.Client(thrift_protocol)
try:
thrift_transport.open()
except Exception as e:
print "connect to hbase thrift failed. (%s)" % e
sys.exit()
return thrift_protocol, thrift_client
def fetch_rows_from_hbase(thrift_protocol, thrift_client, start_row = None):
tscan = ttypes.TScan()
if start_row != None:
tscan.startRow = start_row
tscan.maxVersions = max_versions
tscan.filterString = "FamilyFilter(!=, 'binary:ge')"
scan_id = thrift_client.openScanner(hbase_table_name, tscan)
result = thrift_client.getScannerRows(scan_id, row_limits + 1)
print result
print "=================================================\n"
thrift_client.closeScanner(scan_id)
thrift_protocol.close()
if __name__ == '__main__':
thrift_protocol, thrift_client = create_hbase_connection()
fetch_rows_from_hbase(thrift_protocol, thrift_client)
下面是错误:
回溯(最后一次调用):文件“/load_hbase.py”,第46行,
在里面
从\u hbase(thrift\u协议,thrift\u客户端)文件“/load\u hbase.py”,第37行,从\u hbase获取\u行
scan_id=thrift_client.openScanner(hbase_table_name,tscan)文件“/home/lishaohua/kpn/load_hbase/thrift2/hbase/THBaseService.py”,
第715行,在openScanner中
返回self.recv_openScanner()文件“/home/lishaohua/kpn/load_hbase/thrift2/hbase/THBaseService.py”,第行
735,在recv_openScanner中
result.read(iprot)文件“/home/lishaohua/kpn/load_hbase/thrift2/hbase/THBaseService.py”,第行
3278,已读
fastbinary.decode_binary(self,iprot.trans,(self.类,self.thrift_spec))AttributeError:'TFramedTransport'对象没有
属性“trans”
我在
tttransport.py
中检查代码,TFramedTransport
具有属性self.\uu trans
。如何解决这个问题?我可以简单地将tans
更改为\u trans
,但是还有更多的问题。我使用了TBufferedTransport
而不是TFramedTransport
,并且它起了作用。您可以在下面尝试我的解决方案:
class ThriftConn(object):
def __init__(self, ip, port, service_cls):
self.socket = TSocket.TSocket(ip, port)
self.trans = TTransport.TBufferedTransport(self.socket)
self.protocol = TBinaryProtocol.TBinaryProtocol(self.trans)
self.client = service_cls.Client(self.protocol)
def __enter__(self):
self.trans.open()
def __exit__(self, exception_type, exception_value,
exception_traceback):
self.trans.close()
HBASE_SERVER_CLIENT = ThriftConn(ip, port, THBaseService)
with HBASE_SERVER_CLIENT:
scan = TScan()
scan_id = HBASE_SERVER_CLIENT.client.openScanner(table, scan)