AttributeError:EchoFactory实例没有属性'doStart'

时间:2017-07-26 07:47:48

标签: python twisted

我正在学习Twisted,这是我的第一个服务器示例:

from twisted.internet import protocol, reactor

class Echo(protocol.Protocol):
    def dataReceived(self, data):
        self.transport.write(data)

class EchoFactory(protocol.Protocol):
    def buildProtocal(self, addr):
       return Echo()

reactor.listenTCP(8000, EchoFactory())
reactor.run()

我收到此错误,我尝试重新安装该库但它仍然无效:

Traceback (most recent call last):
File "/home/trieu/Desktop/server.py", line 11, in <module>
reactor.listenTCP(8000, EchoFactory())
File "/usr/lib/python2.7/dist-packages/twisted/internet/posixbase.py", 
line 495, in listenTCP
p.startListening()
File "/usr/lib/python2.7/dist-packages/twisted/internet/tcp.py", line 998, 
in startListening
self.factory.doStart()
AttributeError: EchoFactory instance has no attribute 'doStart'

1 个答案:

答案 0 :(得分:3)

EchoFactory应该延伸protocol.Factory,而不是protocol.Protocol。此外,您在重写的方法名称中有一个拼写错误buildProtocol