thrift-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Roger Meier <ro...@bufferoverflow.ch>
Subject Re: SSL Python Thrift Client Server
Date Wed, 06 May 2015 07:55:10 GMT
Hi sanjeev

please use a more recent version of Thrift, 0.9.2 or master branch.

regards
roger

Quoting sanjeev taran <s_taran@yahoo.com.invalid>:

> Hello,
>
> I am trying to write a SSL enabled Thrift Client Server app and  
> running into issues - errors provided below. I created a self-signed  
> certificate using openssl. Here is my code
>
> Interface_server.py - Server Code:
>
> import sys
> import os
> import json
> sys.path.append("gen-py")
> from InterfaceSvc import InterfaceSvc
> from thrift.transport import TSocket
> from thrift.transport import TSSLSocket
> from thrift.transport import TTransport
> from thrift.protocol import TBinaryProtocol
> from thrift.server import TServer
>
> class ListHandler:
>     def get_lines(self,cnt):
>         print("[Server] Handling client request")
>         return json.dumps("returned from server")
>         #return "Hello from the python server"
>
> handler = ListHandler()
> proc = InterfaceSvc.Processor(handler)
> trans_ep =  
> TSSLSocket.TSSLServerSocket(host='127.0.0.1',port=9099,certfile='/home/hadoop/staran.crt')
> trans_fac = TTransport.TBufferedTransportFactory()
> proto_fac = TBinaryProtocol.TBinaryProtocolFactory()
> server = TServer.TSimpleServer(proc, trans_ep, trans_fac, proto_fac)
> print "Starting Python Server on Port .."
> server.serve()
>
>
> Interface_client.py - Client Code:
>
> import sys
> sys.path.append("gen-py")
> from InterfaceSvc import InterfaceSvc
>
> from thrift.transport import TSSLSocket
> from thrift.transport import TSocket
> from thrift.transport import TTransport
> from thrift.protocol import TBinaryProtocol
>
> #Make a socket
> trans_ep =  
> TSSLSocket.TSSLSocket(host='127.0.0.1',port=9099,ca_certs="/home/hadoop/staran.crt")
> trans_buf = TTransport.TBufferedTransport(trans_ep)
> proto = TBinaryProtocol.TBinaryProtocol(trans_buf)
> client = InterfaceSvc.Client(proto)
>
> #Connect!
> trans_ep.open()
> msg = client.get_lines(2)
> print("[Client] received: %s" % msg)
>
>
> And my InterfaceSrv.thrift file is
>
> service InterfaceSvc {
>  string get_lines(1:i32 cnt)
> }
>
> When I launch the client app, I get the following error on client side:
> [root@mylaptop mydir]# python Interface_server.py &
> [root@mylaptop mydir]# python Interface_client.py
> Traceback (most recent call last):
>   File "Interface_client.py", line 22, in <module>
>     trans_ep.open()
>   File  
> "/usr/lib/python2.6/site-packages/thrift-0.8.0-py2.6-linux-i686.egg/thrift/transport/TSSLSocket.py",
line 87, in  
> open
>     raise TTransportException(type=TTransportException.NOT_OPEN,  
> message=message)
> thrift.transport.TTransport.TTransportException: Could not connect  
> to 127.0.0.1:9099
>
> The server also crashes and I see the following error on the server side:
>
>
> Starting Python Server on Port ..
> ERROR:root:'NoneType' object has no attribute 'read'
> Traceback (most recent call last):
>   File  
> "/usr/lib/python2.6/site-packages/thrift-0.8.0-py2.6-linux-i686.egg/thrift/server/TServer.py",
line 83, in  
> serve
>     self.processor.process(iprot, oprot)
>   File "gen-py/InterfaceSvc/InterfaceSvc.py", line 74, in process
>     (name, type, seqid) = iprot.readMessageBegin()
>   File  
> "/usr/lib/python2.6/site-packages/thrift-0.8.0-py2.6-linux-i686.egg/thrift/protocol/TBinaryProtocol.py",
line 126, in  
> readMessageBegin
>     sz = self.readI32()
>   File  
> "/usr/lib/python2.6/site-packages/thrift-0.8.0-py2.6-linux-i686.egg/thrift/protocol/TBinaryProtocol.py",
line 203, in  
> readI32
>     buff = self.trans.readAll(4)
>   File  
> "/usr/lib/python2.6/site-packages/thrift-0.8.0-py2.6-linux-i686.egg/thrift/transport/TTransport.py",
line 58, in  
> readAll
>     chunk = self.read(sz-have)
>   File  
> "/usr/lib/python2.6/site-packages/thrift-0.8.0-py2.6-linux-i686.egg/thrift/transport/TTransport.py",
line 160, in  
> read
>     self.__rbuf = StringIO(self.__trans.read(max(sz, self.__rbuf_size)))
> AttributeError: 'NoneType' object has no attribute 'read'
> Traceback (most recent call last):
>   File "Interface_server.py", line 45, in <module>
>     server.serve()
>   File  
> "/usr/lib/python2.6/site-packages/thrift-0.8.0-py2.6-linux-i686.egg/thrift/server/TServer.py",
line 89, in  
> serve
>     itrans.close()
>   File  
> "/usr/lib/python2.6/site-packages/thrift-0.8.0-py2.6-linux-i686.egg/thrift/transport/TTransport.py",
line 153, in  
> close
>     return self.__trans.close()
> AttributeError: 'NoneType' object has no attribute 'close'
>
>
> I would appreciate any help you can provide. I have seen examples in  
> Java but not in python and I am not sure what I am doing wrong. The  
> same code without the TSSLSocket pieces works fine.
>
> Regards,
> STaran



Mime
View raw message