[Twisted-Python] attribute error when I am trying to make one factory to send data to another

Jessica Tsui jesadjust at gmail.com
Tue Apr 28 11:28:53 MDT 2015


Hi Daniel,

  Thank you so much for your suggestion. I am quite new to python and
twisted so I am not very certain about how to make it work well. Does that
mean if I change the dataReceived by adding a line to instantiate the
MultiEchoFactory like this, it will work?

def dataReceived(self, data):
    "As soon as any data is received, write it back."
    handlesendermessage = self.factory.app.handle_message(data)

    if handlesendermessage:
        self.transport.write(data)
        MultiEchoFactory()
        MultiEcho().dataReceived(data)


2015-04-29 0:33 GMT+08:00 Louis D. Burr <ldanielburr at me.com>:

> Hi Jessica,
>
> On Apr 28, 2015, at 10:14 AM, Jessica Tsui <jesadjust at gmail.com> wrote:
>
> SNIP
>
>  exceptions.AttributeError: MultiEcho instance has no attribute ‘factory'
>
> SNIP
>
> MultiEcho().dataReceived(sendermessage)
>
> Here you create an instance of the protocol directly, i.e., without having
> instantiated a MutilEchoFactory.  The factory’s buildProtocol method is
> what assigns the factory instance as a member of the protocol
> (self.factory), and since you didn’t create the protocol via a factory, you
> have no factory attribute on your protocol instance.
>
> There are a number of ways to fix this, but generally speaking, you need
> to provide a way for your factories and their protocols to be aware of each
> other.
>
> Hope this helps,
>
> Daniel
> --
> L. Daniel Burr
> ldanielburr at me.com
> (312) 656-8387
>
>
> _______________________________________________
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
> http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20150429/3e92827a/attachment-0002.html>


More information about the Twisted-Python mailing list