简体   繁体   English

扭曲 - Python3 类型错误:__init__() 缺少 1 个必需的位置参数:“工厂”

[英]Twisted - Python3 TypeError: __init__() missing 1 required positional argument: 'factory'

I'm writing some python software that polls a modbus connection and stores the data in an SQL database.我正在编写一些 python 软件来轮询 modbus 连接并将数据存储在 SQL 数据库中。 To see if the machine is working as a quick test, I'm making a simple console style "HMI" that you can telnet into.为了查看机器是否可以作为快速测试工作,我正在制作一个简单的控制台样式“HMI”,您可以通过 telnet 进入。 Here is the offending code, and error.这是有问题的代码和错误。

from twisted.internet.protocol import Protocol, Factory
from twisted.internet.endpoints import TCP4ServerEndpoint
from twisted.internet import reactor
from twisted.internet import task
from twisted.internet import protocol

#from screenhelp import ScreenHelp ** Not relevant to error


class Screen(Protocol):

    def __init__(self, factory):
        self.factory = factory
        self.connection = False
        self.loop = task.LoopingCall(screenRefresh)
        self.loopDeferred = None
        self.stack = []
        self.cs = ScreenHelp()

    def connectionMade(self):
        self.loopDeferred = self.loop.start(self,5)

    def connectionLost(self, reason):
        self.loop.stop(self)

    def dataReceived(self, data):
        self.stack.append(data)

    def screenRefresh(self):

        #self.transport.write(self.cs.clr()) ** Not relevent - issues clear screen command.
        for x in self.stack:
            self.transport.write(x)

class ScreenFactory(Factory):
    def buildProtocol(self, addr):
        return Screen()


def main():
    endpoint1 = TCP4ServerEndpoint(reactor, 64000)
    endpoint1.listen(ScreenFactory)
    reactor.listenTCP(5000, fact)
    reactor.run()


if __name__ == "__main__":
     main()

The error is:错误是:

File "/usr/lib/python3/dist-packages/twisted/internet/protocol.py", line 135, in buildProtocol
    p = self.protocol()
TypeError: __init__() missing 1 required positional argument: 'factory'

Thanks in advance for any help!在此先感谢您的帮助!

This may be related to your problem:这可能与您的问题有关:

In this section, you call Screen() without any arguments:在本节中,您调用Screen()不带任何参数:

class ScreenFactory(Factory):
    def buildProtocol(self, addr):
        return Screen()

However, earlier you defined Screen to take a factory argument:但是,之前您定义Screen以采用factory参数:

class Screen(Protocol):
    def __init__(self, factory):
        ...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python3 - Django2 - TypeError: __init__() 缺少 1 个必需的位置参数:'on_delete' - Python3 - Django2 - TypeError: __init__() missing 1 required positional argument: 'on_delete' TypeError:__init __()缺少1个必需的位置参数:“ to” - TypeError: __init__() missing 1 required positional argument: 'to' TypeError:__init __()缺少1个必需的位置参数 - TypeError: __init__() missing 1 required positional argument Python 问题:TypeError:__init__() 缺少 1 个必需的位置参数:'brett' - Python Problem: TypeError: __init__() missing 1 required positional argument: 'brett' Python - __init__() 缺少 1 个必需的位置参数: - Python - __init__() missing 1 required positional argument: TypeError:__init __()缺少1个必需的位置参数:分支,但提供了参数 - TypeError: __init__() missing 1 required positional argument: branches, but argument is supplied Scrapy:TypeError:__ init __()缺少1个必需的位置参数:'settings' - Scrapy: TypeError: __init__() missing 1 required positional argument: 'settings' 类型错误:__init__() 缺少 1 个必需的位置参数:“单位” - TypeError: __init__() missing 1 required positional argument: 'units' Tweepy错误 - TypeError:__ init __()缺少1个必需的位置参数:'listener' - Tweepy error - TypeError: __init__() missing 1 required positional argument: 'listener' TypeError:__init__() 缺少 1 个必需的位置参数:'successor - TypeError: __init__() missing 1 required positional argument: 'successor
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM