[Twisted-Python] Problem with ClientFactory

Michal Chruszcz troll at pld-linux.org
Thu Jan 27 08:40:55 EST 2005

It seems like on Wednesday 26 of January 2005 17:43, Itamar Shtull-Trauring 
> On Wed, 2005-01-26 at 16:57 +0100, Michal Chruszcz wrote:
> > class Factory(ClientFactory):
> >     protocol = Protocol
> >     def startedConnecting(self, connector):
> >         print "Connecting..."
> >
> >     def buildProtocol(self, addr):
> >         print "Connected."
> The problem is you overrode buildProtocol. Default buildProtocol returns
> self.protocol(), but if you override it you need to create and return a
> protocol instance yourself.

Indeed. I should have checked the sources first. Anyway, thanks for info.

Unfortunately, just after fixing above problem, I occurred one really 
annoying "feature". When I try to connect to a host/port which doesn't 
support SSL connections, I receive an exception which I can't catch. The 
traceback looks like this:
  File "/usr/lib/python2.4/site-packages/twisted/python/context.py", line 
43, in callWithContext
  File "/usr/lib/python2.4/site-packages/twisted/internet/default.py", line 
535, in _doReadOrWrite
  File "/usr/lib/python2.4/site-packages/twisted/internet/tcp.py", line 133, 
in doWrite
  File "/usr/lib/python2.4/site-packages/twisted/internet/abstract.py", line 
99, in doWrite
--- <exception caught here> ---
  File "/usr/lib/python2.4/site-packages/twisted/internet/tcp.py", line 137, 
in writeSomeData
  File "/usr/lib/python2.4/site-packages/twisted/internet/tcp.py", line 264, 
in writeSomeData
OpenSSL.SSL.Error: [('SSL routines', 'SSL3_GET_RECORD', 'wrong version 

Is it possible to catch it? I put a try...except statement near the reactor 
calls, but it didn't work. I was trying to find somewhere else an answer to 
my question, however I failed after a couple of hours of searching.

I'm not saying it's a big problem, but it "doesn't look nice" and a good 
program shouldn't behave in this way.
Michal Chruszcz -=- Seen at http://1lo.sanok.pl/~troll/gallery.php

More information about the Twisted-Python mailing list