RPC崩溃与AttributeError:'NoneType'对象没有属性'调用'(RPC crashes with AttributeError: '

编程入门 行业动态 更新时间:2024-10-24 12:23:26
RPC崩溃与AttributeError:'NoneType'对象没有属性'调用'(RPC crashes with AttributeError: 'NoneType' object has no attribute 'call')

我正在尝试开发一个查询platform.historian的代理,但在使用RPC查询方法时收到此错误消息:AttributeError:'NoneType'对象没有属性'call'

class TCMAgent(Agent): def __init__(self, config_path, **kwargs): super(TCMAgent, self).__init__(**kwargs) self.config = utils.load_config(config_path) self.site = self.config.get('campus') self.building = self.config.get('building') self.unit = self.config.get('unit') self.subdevices = self.config.get('subdevices') self.subdevice = self.subdevices[0] ... ... def test_api(): '''To test Volttron APIs''' import os topic_tmpl = "{campus}/{building}/{unit}/{subdevice}/{point}" tcm = TCMAgent(os.environ.get('AGENT_CONFIG')) topic1 = topic_tmpl.format(campus='PNNL', building='SEB', unit='AHU1', subdevice='VAV123A', point='MaximumZoneAirFlow') result = tcm.vip.rpc.call('platform.historian', 'query', topic=topic1, count=20, order="LAST_TO_FIRST").get(timeout=100) assert result is not None if __name__ == '__main__': # Entry point for script #sys.exit(main()) test_api()

更新下面的错误跟踪:

2016-07-19 14:58:31,362 volttron.platform.vip.agent.core DEBUG: publickey is None 2016-07-19 14:58:31,362 volttron.platform.vip.agent.core DEBUG: secretkey is None Traceback (most recent call last): File "/home/hngo/volttron/examples/TCMAgent/tcm/agent.py", line 236, in <module> test_api() File "/home/hngo/volttron/examples/TCMAgent/tcm/agent.py", line 230, in test_api order="LAST_TO_FIRST").get(timeout=100) File "/home/hngo/volttron/volttron/platform/vip/agent/subsystems/rpc.py", line 303, in call request, result = self._dispatcher.call(method, args, kwargs) AttributeError: 'NoneType' object has no attribute 'call'

I am trying to develop an agent that queries platform.historian but got this error message when using RPC query method: AttributeError: 'NoneType' object has no attribute 'call'

class TCMAgent(Agent): def __init__(self, config_path, **kwargs): super(TCMAgent, self).__init__(**kwargs) self.config = utils.load_config(config_path) self.site = self.config.get('campus') self.building = self.config.get('building') self.unit = self.config.get('unit') self.subdevices = self.config.get('subdevices') self.subdevice = self.subdevices[0] ... ... def test_api(): '''To test Volttron APIs''' import os topic_tmpl = "{campus}/{building}/{unit}/{subdevice}/{point}" tcm = TCMAgent(os.environ.get('AGENT_CONFIG')) topic1 = topic_tmpl.format(campus='PNNL', building='SEB', unit='AHU1', subdevice='VAV123A', point='MaximumZoneAirFlow') result = tcm.vip.rpc.call('platform.historian', 'query', topic=topic1, count=20, order="LAST_TO_FIRST").get(timeout=100) assert result is not None if __name__ == '__main__': # Entry point for script #sys.exit(main()) test_api()

Update Error Trace below:

2016-07-19 14:58:31,362 volttron.platform.vip.agent.core DEBUG: publickey is None 2016-07-19 14:58:31,362 volttron.platform.vip.agent.core DEBUG: secretkey is None Traceback (most recent call last): File "/home/hngo/volttron/examples/TCMAgent/tcm/agent.py", line 236, in <module> test_api() File "/home/hngo/volttron/examples/TCMAgent/tcm/agent.py", line 230, in test_api order="LAST_TO_FIRST").get(timeout=100) File "/home/hngo/volttron/volttron/platform/vip/agent/subsystems/rpc.py", line 303, in call request, result = self._dispatcher.call(method, args, kwargs) AttributeError: 'NoneType' object has no attribute 'call'

最满意答案

您的代理不会连接到平台,也不会“启动”。 这是你在这里处理的问题。 我不知道你是如何指定你的vip地址连接到运行平台的。

您需要先运行代理,然后才能允许它进行rpc调用。 以下内容,以https://github.com/VOLTTRON/volttron/blob/develop/examples/SimpleForwarder/simpleforwarder/simpleforwarder.py#L118为例进行修改。

destination_vip="tcp://127.0.0.1:22916?serverkey=blah&publickey=wah&privatekey=nah agent = TMCAgent(config_path=cfg_path, identity=tester, address=destination_vip) event = gevent.event.Event() # agent.core.run set the event flag to true when agent is running gevent.spawn(agent.core.run, event) # Wait until the agent is fully initialized and ready to # send and receive messages. event.wait(timeout=3)

Your agent doesn't connect to the platform nor does it "start". That is the issue you are dealing with here. I don't see how you are specifying your vip address to connect to the running platform either.

You need to run your agent before you are able to allow it to make rpc calls. Something like the following, modified from https://github.com/VOLTTRON/volttron/blob/develop/examples/SimpleForwarder/simpleforwarder/simpleforwarder.py#L118 as an example.

destination_vip="tcp://127.0.0.1:22916?serverkey=blah&publickey=wah&privatekey=nah agent = TMCAgent(config_path=cfg_path, identity=tester, address=destination_vip) event = gevent.event.Event() # agent.core.run set the event flag to true when agent is running gevent.spawn(agent.core.run, event) # Wait until the agent is fully initialized and ready to # send and receive messages. event.wait(timeout=3)

更多推荐

本文发布于:2023-08-06 19:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1455686.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   对象   AttributeError   NoneType   RPC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!