Thriftpy / thriftpy2

Pure python approach of Apache Thrift.
MIT License
567 stars 90 forks source link

correspondence between thriftpy2 and thrift versions #209

Closed yiqijiu closed 1 year ago

yiqijiu commented 1 year ago

"As the title suggests, I want to know the relationship between thriftpy2 and thrift versions. Currently, when I use HappyBase to access HBase, an error is reported: TTransportException(type=4,message='Tsocket read 0 bytes'), and the thriftpy2 version is 0.4.16, which is the latest version I am using. Then I found that HBase's thrift uses version 0.14.1. Which version of thriftpy2 should I use?" thx

ethe commented 1 year ago

You should always use the latest version of thriftpy2, if you could always reproduce this issue, please post a minimal case here, I would like to test it later.

yiqijiu commented 1 year ago

Thank you for your reply. I am using the last version of HappyBase with the latest version of thriftpy2 as the underlying connection to the HBase Thrift server, but encountered an error. The version of HBase Thrift is 0.14.1 and the version of HBase is 2.2.3.The following is an example of my code.

yiqijiu commented 1 year ago
import happybase

# Create a connection to the HBase using HappyBase client
connection = happybase.Connection('localhost', port=9090)

# Create a table named 'mytable'
table_name = 'mytable'
column_family = 'cf'
connection.create_table(
    table_name,
    {column_family: dict()},
)

# Get the table object for 'mytable'
table = connection.table(table_name)

# Insert a row of data into 'mytable'
table.put(b'row1', {b'cf:col1': b'value1', b'cf:col2': b'value2'})

# Get a row of data from 'mytable'
row = table.row(b'row1')
print(row[b'cf:col1'])  # output: b'value1'

# Close the connection
connection.close()
yiqijiu commented 1 year ago

Thank you, I have resolved the issue, it was my mistake. The solution was to replace the hbase.thrift of HappyBase with the one in the hbase cluster, and ensure that the connection protocol and cluster configuration are consistent. Sorry for bothering you for so long.

aisk commented 1 year ago

`TTransportException(type=4,message='Tsocket read 0 bytes')` means the server closed the TCP connection without sending anything. This will happened when the server can't under standing the request protocol (like it's not a thrift server, or have different protocol / transport config), or just got an error when processing the request and the IDL for this request have no exception assumed.

Or, this is a "502" in HTTP protocol.