Example Apache Thrift service using HTTPS in Python

I managed to find examples for deploying services using Apache Thrift that use SSL as a transport .. in Java. But not in Python.

I would like to use Apache Thrift to generate the template code for calling services written in Python, which is called from Android. Transportation must be HTTPS.

Any clues where can I find something like this?

+4
source share
2 answers

I used Thrift with PHP, Java, and Python, and you may notice that the worst part of working with Thrift is its documentation. Part of the official example, available in different languages: The official source code guide . Here are a few web pages that describe in more detail how to implement the client / server throttling protocol:

Securing your connection over SSL will mean changing your server / client by adding a couple of new lines, here is an example in Java:

It's not hard to rewrite the latest python code

+1
source

Your client will look something like this:

from thrift.transport import THttpClient from thrift.transport import TTransport from thrift.protocol import TBinaryProtocol from tutorial import Calculator transport = THttpClient.THttpClient('https://your-service.com') transport = TTransport.TBufferedTransport(transport) protocol = TBinaryProtocol.TBinaryProtocol(transport) client = Calculator.Client(protocol) # Connect! transport.open() client.ping() 

You can use a proxy in front of your service to terminate the SSL connection, and then send an HTTP request to your server, which looks something like this:

 from thrift.protocol import TBinaryProtocol from thrift.server import THttpServer from tutorial import CalculatorHandler # assuming you defined this handler = CalculatorHandler() processor = Calculator.Processor(handler) pfactory = TBinaryProtocol.TBinaryProtocolFactory() server = THttpServer.THttpServer( processor, ('', 9090), pfactory ) print('Starting the server...') server.serve() print('done.') 
+1
source

All Articles