【发布时间】:2021-08-03 12:47:05
【问题描述】:
我正在使用 Autobahn Python 连接到 Crossbar 路由器。我希望处理交叉开关路由器在网络上不可用的情况。当使用基于类的组件时,我能够处理连接错误,但是在使用功能组件时,我无法捕获和处理这些异常。
from autobahn.asyncio.component import Component
component = Component(transports="no_existent_url:3000",
realm=realm, authentication=authentication)
component.on('join', onJoinHandler)
# Called on exception when connected
component.on('leave', onLeaveHandler)
# Never called
component.on('connectfailure', onFailureHandler)
# Never called
component.on('disconnect', onDisconnectHandler)
component.start()
错误出现在控制台输出中:
Error in connection Multiple exceptions: [Errno 111] Connect call failed ('no_existent_url', 3000), [Errno 99] Cannot assign requested address
Connection failed: OSError: Multiple exceptions: [Errno 111] Connect call failed ('no_existent_url', 3000), [Errno 99] Cannot assign requested address
Component failed: Exhausted all transport connect attempts
【问题讨论】:
-
你试过using try/except吗?
-
@ExtraFishness 是的,异常不会在主运行循环中引发,因此 try/except 不起作用
标签: python python-asyncio autobahn