Volttron 在尝试发布时抛出属性错误

Volttron throws an Attribute error when attempting to publish

我正在将 Scapy 与 Volttron 相结合,我想在数据包进入并具有某些功能时发布到一个主题。但是,我一直 运行ning 这个错误:

Traceback (most recent call last): File "sniff.py", line 373, in sys.exit(main()) File "sniff.py", line 342, in main utils.vip_main(sniffer, version=version) File "/home/jenny/workspace/volttron/volttron/platform/agent/utils.py",

line 314, in vip_main version=version, **kwargs) File "sniff.py", line 336, in sniffer Sniffer(**kwargs) File "sniff.py", line 138, in init self.vip.pubsub.publish('pubsub', "some/topic", message="blah")
File "/home/jenny/workspace/volttron/volttron/platform/vip/agent/subsystems/pubsub.py",

line 602, in publish self._save_parameters(result.ident, **kwargs)
File "/home/jenny/workspace/volttron/volttron/platform/vip/agent/subsystems/pubsub.py", line 706, in _save_parameters event = self.core().schedule(end_time, self._cancel_event, result_id)
File "/home/jenny/workspace/volttron/volttron/platform/vip/agent/core.py", line 409, in schedule self._schedule_callback(deadline, event) File "/home/jenny/workspace/volttron/volttron/platform/vip/agent/core.py", line 417, in _schedule_callback self._schedule_event.set()

AttributeError: 'NoneType' object has no attribute 'set'

我找到的最接近解决方案的地方是。但是,我注意到它们并不是完全相同的问题,因此当我尝试那里提供的解决方案但它对我不起作用时,我并不感到惊讶。

我的代码如下所示:

def sniffer(config_path, **kwargs):

    ''' Initializations '''
    global pkt_counter
    global IP_counter
    # Defined other parameters here

    class Sniffer(Agent):
        def __init__(self, **kwargs):
            super(Sniffer, self).__init__(**kwargs)
            # I am just testing the publish function here
            self.vip.pubsub.publish('pubsub', "some/topic", message="blah")
            sniff(count=0, iface=conf.iface, prn = self.pkt_action, store=0)


        def pkt_action(self, pkt):
            #Process every packet, updates values and rises and alert if necessary 
            # some checks are run here and later a publish is called

有人可以告诉我我做错了什么吗?

编辑:我没有添加我想要 运行 这个脚本,因为我会在终端上添加一个简单的 python 脚本(例如 python somescript.py ): 无需安装。我尝试这样做的原因是我在安装代理并启动它时遇到错误。该平台不允许 Scapy 创建和连接到套接字。

您正试图在不期望的上下文中使用 vip 模块。直到启动代理或配置事件被触发,代理的生命周期才真正开始执行。尝试将发布放在这些上下文中。

以下摘录自位于以下位置的 VOLTTRON readthedocs 站点:https://volttron.readthedocs.io/en/develop/devguides/agent_development/Agent-Development-Cheatsheet.html#agent-lifecycle-events

Core Agent Functionality These tools volttron.platform.vip.agent module. Try importing

Agent Lifecycle Events Each agent has four events that are triggered at different stages of its life. These > are onsetup, onstart, onstop, and onfinish. Registering callbacks to these events are commonplace in agent development, with onstart being the most frequently used.

The easiest way to register a callback is with a function decorator:


@Core.receiver('onstart')
def function(self, sender, **kwargs):
    function_body