[Twisted-Python] getObjectAtSSL: Exception

Ruslan Spivak alienoid at is.lg.ua
Mon Jul 21 17:43:48 EDT 2003


Hello!

Here is the simple server:

from twisted.spread import pb
from twisted.internet import app, reactor
from OpenSSL import SSL

class ServerContextFactory:

    def getContext(self):
        """Create an SSL context.

        This is a sample implementation that loads a certificate from a file
        called 'server.pem'."""
        ctx = SSL.Context(SSL.SSLv23_METHOD)
        ctx.use_certificate_file('server.pem')
        ctx.use_privatekey_file('server.pem')
        return ctx
 
class Server(pb.Root):
    def __init__(self):
        self.client = None
       
    def checkpoint(self):
        self.client.callRemote("printClientMsg", "Hello from 
Server.checkpoint")
        reactor.callLater(2, self.checkpoint)
       
    def remote_printServerMsg(self, client, msg):
        print "Server got: %s" % msg
        self.client = client
        client.callRemote("printClientMsg", "Hello from 
Server.printServerMsg")
        reactor.callLater(2, self.checkpoint)
       
if __name__ == "__main__":
    appl = app.Application("pbtest")
    appl.listenSSL(33333, pb.BrokerFactory(Server()), 
ServerContextFactory())
    appl.run()



When i try to run pbclient.py:

from twisted.spread import pb
from twisted.internet import reactor

class ClientCall(pb.Referenceable):
    def remote_printClientMsg(self, msg):
        print "Client: %s" % msg

def got_obj(obj, c):
    obj.callRemote("printServerMsg", c, "Hello from Client")
       
c = ClientCall()
def1 = pb.getObjectAtSSL("localhost", 33333, 30)
def1.addCallback(got_obj, c)
reactor.run()

I get:

Traceback (most recent call last):
  File "pbclient.py", line 12, in ?
    def1 = pb.getObjectAtSSL("localhost", 33333, 30)
  File "/usr/lib/python2.2/site-packages/twisted/spread/pb.py", line 
1190, in getObjectAtSSL
    reactor.connectSSL(host, port, bf, timeout)
  File "/usr/lib/python2.2/site-packages/twisted/internet/default.py", 
line 260, in connectSSL
    c.connect()
  File "/usr/lib/python2.2/site-packages/twisted/internet/base.py", line 
504, in connect
    self.transport = transport = self._makeTransport()
  File "/usr/lib/python2.2/site-packages/twisted/internet/ssl.py", line 
173, in _makeTransport
    return Client(self.host, self.port, self.bindAddress, 
self.contextFactory, self, self.reactor)
  File "/usr/lib/python2.2/site-packages/twisted/internet/ssl.py", line 
104, in __init__
    tcp.Client.__init__(self, host, port, bindAddress, connector, reactor)
  File "/usr/lib/python2.2/site-packages/twisted/internet/tcp.py", line 
430, in __init__
    self._finishInit(whenDone, skt, err, reactor)
  File "/usr/lib/python2.2/site-packages/twisted/internet/ssl.py", line 
122, in _finishInit
    self.startTLS(self.ctxFactory)
  File "/usr/lib/python2.2/site-packages/twisted/internet/tcp.py", line 
303, in startTLS
    holder = Connection.startTLS(self, ctx)
  File "/usr/lib/python2.2/site-packages/twisted/internet/tcp.py", line 
190, in startTLS
    self.socket = SSL.Connection(ctx.getContext(), self.socket)
AttributeError: 'int' object has no attribute 'getContext'

What's wrong?
Your help is very appreciated. Thanks in advance.

Best regards,
Ruslan





More information about the Twisted-Python mailing list