gpt4 book ai didi

python - 在 crossbar autobahn 上订阅 python 主题

转载 作者:行者123 更新时间:2023-12-01 07:03:01 25 4
gpt4 key购买 nike

我是一个横栏菜鸟。我正在尝试使用 python 中的高速公路和 crossbar 订阅一个主题。

交叉栏 URL 为“wss://******.******.org/ws/”,主题为 c******d。

没有信号主题,每个调用都会转到这个主题。

我在那里发现了一些代码https://autobahn.readthedocs.io/en/latest/并尝试去适应它。

from autobahn.twisted.component import Component
from twisted.internet.defer import inlineCallbacks
from autobahn.twisted.component import Component
from autobahn.twisted.component import run

#component with my crossbar url :

component = Component(
transports=u"wss://******.******.org/ws/",
realm=u"realm1",
)

@component.on_join
@inlineCallbacks
def joined(session,details):
print("session ready")

def oncounter(count):
print("event received: {0}", count)

try:
yield session.subscribe(oncounter, u'c******d') #here my topic
print("subscribed to topic")
except Exception as e:
print("could not subscribe to topic: {0}".format(e))

if __name__ == "__main__":
run([component])

我收到此错误。似乎没有什么能正常工作。

2019-10-25T14:38:07+0200 SSL error: certificate verify failed (in tls_process_server_certificate)
2019-10-25T14:38:07+0200 TLS failure: certificate verify failed
2019-10-25T14:38:07+0200 Stopping factory <autobahn.twisted.websocket.WampWebSocketClientFactory object at 0x000002B693A58>
2019-10-25T14:38:09+0200 connecting once using transport type "websocket" over endpoint "tcp"
2019-10-25T14:38:09+0200 Starting factory <autobahn.twisted.websocket.WampWebSocketClientFactory object at 0x000002B693A58>
2019-10-25T14:38:09+0200 SSL error: certificate verify failed (in tls_process_server_certificate)
2019-10-25T14:38:09+0200 TLS failure: certificate verify failed
2019-10-25T14:38:09+0200 Stopping factory <autobahn.twisted.websocket.WampWebSocketClientFactory object at 0x000002B693A58>
2019-10-25T14:38:12+0200 connecting once using transport type "websocket" over endpoint "tcp"
2019-10-25T14:38:12+0200 Starting factory <autobahn.twisted.websocket.WampWebSocketClientFactory object at 0x000002B693A58>

正如我所提到的,我对此很陌生,因此对上述内容的任何见解将不胜感激!

最佳答案

我认为你想做的是:

import sys 
import asyncio
from autobahn.asyncio.wamp import ApplicationSession, ApplicationRunner
import autobahn.wamp


class Component(ApplicationSession):

"""
An application component that subscribe to a topic
and print messages

"""
async def onJoin(self, details):

def onmessage(*args, **kwargs):
print ("message received kwargs= "+str(kwargs))

await self.subscribe(onmessage, "c******d")

def onDisconnect(self):

asyncio.get_event_loop().stop()

if __name__ == '__main__':

url = u"wss://************.org/ws/"
realm = u"realm1"
runner = ApplicationRunner(url, realm)
runner.run(Component,'debug')

关于python - 在 crossbar autobahn 上订阅 python 主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58559079/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com