[Twisted-Python] exceptions.AttributeError: 'NoneType' object has no attribute 'write'

Johann Borck johann.borck at densedata.com
Tue Oct 18 11:42:43 EDT 2005


Stefano Canepa wrote:

>
>class Receiver(pb.Root, HL7LLPClientProtocol):
>
>  
>
first of all, i think your pb.Root shouldn't be your protocol, you get
this error because you assume that your Receiver instance is the
protocol. PB uses it's own protocol, there is no use in deriving your
Receiver from your protocol,  I even think it's not possible at all to
implement it that way, and even if it worked it'd be confusing

def __init__(self):
    HL7LLPClientProtocol.__init__(self)

btw: AttributeError: class HL7LLPClientProtocol has no attribute
'__init__'      is what i get, if i don't comment out the above line -
there is no __init__ in that class and in LineReceiver and it's bases
(at least not in my version of twisted, but if you don't get this error,
there must be one somewhere)

>        
>    def remote_sendToTCA(self, msg):
>
>        self.delimiter = "\x02"
>        
>        ## if DEBUG:
>        print 'sending to TCA:', msg
>        # Create creator and connect
>        clientCreator = protocol.ClientCreator(reactor,  
>                        HL7LLPClientProtocol)
>  
>
Here you give the HL7LLPClientProtocol to the client creator, NOT your
Receiver - so you can't call self.sendMsg on your Receiver-instance
(which is good)

>        d = clientCreator.connectTCP(SERVER, PORT)
>  
>
this deferred returns a _new_ instance of the HL7LLPClientProtocol
protocol-class, and _that_ instance has an initialized transport, not
your Receiver-instance, where you call self.sendMsg on.  Further you
don't use addCallback like you do it, you have to use it like:
addCallback(self.method, arg1, arg2, ... ), addCallback wants the
_method_ not it's result.   you have to write a method that gets the
instance of your Protocol from the deferred, and call sendMsg on that,
something like:

...

    clientCreator = protocol.ClientCreator(reactor, HL7LLPClientProtocol)
    d = clientCreator.connectTCP(SERVER, PORT)
    d.addCallback(self.getProto,msg,RETRIES)
    return msg

  def getProto(self,proto,msg,retries):
	proto.sendMsg(msg,retries)


moreover your Protocol should implement lineReceived - that is the next
error i got, running this. Maybe you read the twisted docs about
deferreds and PB.  :)

i hope this helps




More information about the Twisted-Python mailing list