подписаться на тему в питоне на перекладине автобана - PullRequest
1 голос
/ 25 октября 2019

Я нуб в перекладине. Я пытаюсь подписаться на тему, используя автобан и поперечину в Python.

URL-адрес поперечины - "wss: //******.******.org/ws/", а тема - c ****** d.

Нет тем для сигнализации, все звонки идут на эту тему c ****** г.

Я нашел там несколько фрагментов кода 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>

Как уже упоминалось, я новичок в этом, поэтому любые идеи по поводу вышеизложенного будут с благодарностью!

1 Ответ

1 голос
/ 29 октября 2019

Я думаю, что вы пытаетесь сделать:

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')

...