You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@thrift.apache.org by "Knick, Scott E CTR USARMY RCERT-EUR (US)" <sc...@mail.mil> on 2013/06/17 14:28:06 UTC

Error with TSSLServerSocket (Python 2.6) (UNCLASSIFIED)

Classification: UNCLASSIFIED
Caveats: NONE

Hello,

I'm having some issues trying to use the TSSLServerSocket class in the Thrift Python APIs (I'm using Thrift 0.9.0 with Python 2.6). I have previously successfully used Thrift for a Perl/PHP client and C++ server, though this is the first time I have tried to use SSL with Thrift and the first time I've tried to use Python for my server.

Basically, I'm experiencing an error whenever I try to run the following server and then connect to it with a Python client. (Note that I've verified that I can connect just fine when I use a TServerSocket instead of TSocket.)

    #!/usr/bin/python
    import sys
    sys.path.append("generated")
    
    import thrift.transport.TSSLSocket
    import thrift.transport.TTransport
    import thrift.protocol.TBinaryProtocol
    import thrift.server.TServer
    
    import My.Class
    
    class MyHandler:
        def say(self, greeting):
            print greeting
    
    handler = MyHandler()
    processor = My.Class.Processor(handler)
    transport = thrift.transport.TSSLSocket.TSSLServerSocket("localhost", 9090, "server.crt")
    tfactory = thrift.transport.TTransport.TBufferedTransportFactory()
    pfactory = thrift.protocol.TBinaryProtocol.TBinaryProtocolFactory()
    
    server = thrift.server.TServer.TSimpleServer(processor, transport, tfactory, pfactory)
    
    print 'Starting the server...'
    server.serve()
    print 'done.'

Here is the client code:

    #!/usr/bin/python
    import sys
    sys.path.append("generated")
    
    import thrift.Thrift
    import thrift.transport.TSSLSocket
    import thrift.transport.TTransport
    import thrift.protocol.TBinaryProtocol
    
    import My.Class
    
    try:
        transport = thrift.transport.TSSLSocket.TSSLSocket("localhost", 9090, False)
        transport = thrift.transport.TTransport.TBufferedTransport(transport)
        protocol = thrift.protocol.TBinaryProtocol.TBinaryProtocol(transport)
        
        client = My.Class.Client(protocol)
        
        transport.open()
        
        client.say("Hi, this is Scott!")
        
        transport.close()
    except thrift.Thrift.TException, tx:
        print '%s' % (tx.message)

Whenever I run the server and then run the client script, I get the following error:

    Starting the server...
    ERROR:root:'NoneType' object has no attribute 'read'
    Traceback (most recent call last):
      File "/usr/lib64/python2.6/site-packages/thrift/server/TServer.py", line 84, in serve
        self.processor.process(iprot, oprot)
      File "/home/knicksc/generated/My/Class.py", line 72, in process
        (name, type, seqid) = iprot.readMessageBegin()
      File "/usr/lib64/python2.6/site-packages/thrift/protocol/TBinaryProtocol.py", line 126, in readMessageBegin
        sz = self.readI32()
      File "/usr/lib64/python2.6/site-packages/thrift/protocol/TBinaryProtocol.py", line 206, in readI32
        buff = self.trans.readAll(4)
      File "/usr/lib64/python2.6/site-packages/thrift/transport/TTransport.py", line 58, in readAll
        chunk = self.read(sz - have)
      File "/usr/lib64/python2.6/site-packages/thrift/transport/TTransport.py", line 159, 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 "./server.py", line 27, in <module>
        server.serve()
      File "/usr/lib64/python2.6/site-packages/thrift/server/TServer.py", line 90, in serve
        itrans.close()
      File "/usr/lib64/python2.6/site-packages/thrift/transport/TTransport.py", line 152, in close
        return self.__trans.close()
    AttributeError: 'NoneType' object has no attribute 'close'

The client script shows the following error when this happens:

    Could not connect to localhost:9090

What am I missing? Any help is appreciated.

--
Scott Knick


Classification: UNCLASSIFIED
Caveats: NONE