初次写,写的比较懒。凑合看吧。
遇到的坑
貌似Python用thrif默认的gen-py会有问题。
from md.bxCity import CityService
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
def main():
# Make socket
transport = TSocket.TSocket('localhost', 55020)
# Buffering is critical. Raw sockets are very slow
transport = TTransport.TBufferedTransport(transport)
# Wrap in a protocol
protocol = TBinaryProtocol.TBinaryProtocol(transport)
# Create a client to use the protocol encoder
client = CityService.Client(protocol)
# Connect!
transport.open()
print(client.getCityAllInfo(11111))
# Close!
transport.close()
main()