我正在编写一个python脚本来从hbase加载数据。但事情似乎出了问题 thrift
生成的文件。这是我的密码:
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\u hbase.py”,第46行,在fetch\u rows\u from\u hbase(thrift\u protocol,thrift\u client)文件“/load\u hbase.py”,第37行,在fetch\u rows\u from\u hbase scan\u id=thrift\u client.openscanner(hbase\u table\u name,tscan)文件“/home/lishaohua/kpn/load\u hbase/thrift2/hbase/thbaseservice.py”,第715行,在openscanner return self.recv\u openscanner()file“/home/lishaohua/kpn/load\u hbase/thrift2/hbase/thbaseservice.py”行735中,在recv\u openscanner result.read(iprot)file“/home/lishaohua/kpn/load\u hbase/thrift2/hbase/thbaseservice.py”行3278中,读取fastbinary.decode\u binary(self,iprot.trans,(self.class,self.thrift\u spec)attributeerror:“tframedtransport”对象没有属性“trans”
我把密码签入 TTransport.py
, TFramedTransport
具有属性 self.__trans
. 如何解决这个问题?我可以改变 tans
至 __trans
,但问题更多。
1条答案
按热度按时间vom3gejh1#
我曾经
TBufferedTransport
而不是TFramedTransport
,而且成功了。您可以尝试下面的解决方案: