[Twisted-Python] exceptions.AttributeError: 'NoneType' object has no attribute 'write'
Stefano Canepa
sc at linux.it
Tue Oct 18 12:12:46 EDT 2005
Il giorno mar, 18/10/2005 alle 17.42 +0200, Johann Borck ha scritto:
> 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)
Sorry, I did an error pasting
> >
> > 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)
>
Thanks I arrived a the point with the help of Jp on IRC and reading docs
once again.
> 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
It helped.
Thanks
Stefano
--
Stefano Canepa aka sc: sc at linux.it http://www.stefanocanepa.it
Three great virtues of a programmer: laziness, impatience and hubris.
Le tre grandi virtù di un programmatore: pigrizia, impazienza e
arroganza. (Larry Wall)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20051018/3c830169/attachment.pgp
More information about the Twisted-Python
mailing list