我正在使用pysher库连接到websocket。有时,我可以看到我没有收到任何数据,并且我的journalctl
中存在此错误:
Connection: Received error 4201
Exception in thread PysherEventLoop:
Traceback (most recent call last):
File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/local/lib/python3.6/dist-packages/pysher/connection.py", line 102, in run
self._connect()
File "/usr/local/lib/python3.6/dist-packages/pysher/connection.py", line 126, in _connect
self.socket.run_forever(**self.socket_kwargs)
File "/usr/local/lib/python3.6/dist-packages/websocket/_app.py", line 207, in run_forever
raise WebSocketException("socket is already opened")
websocket._exceptions.WebSocketException: socket is already opened
Failed send ping: socket is already closed.
我的脚本如下:
import pysher
# some code like logger, etc...
def my_func(*args, **kwargs):
print("processing Args:", args)
print("processing Kwargs:", kwargs)
def connect_handler(data):
channel = pusher.subscribe('mychannel')
channel.bind('myevent', my_func)
try:
pusher = pysher.Pusher(req_appkey)
pusher.connection.bind('pusher:connection_established', connect_handler)
pusher.connect()
logger.info('Connection sucessfully established.')
while not killer.kill_now:
time.sleep(1)
except Exception as e:
logger.info('Unexpected error occurred.')
logger.info('Error: ', e)
我将其作为linux服务启动,当脚本未运行时它将自动启动。但是,即使在我的journalctl中发生此错误(无法被我的尝试clausula捕获),脚本循环仍在运行。
此错误是什么意思,我的websocket如何同时打开和关闭?有人可以解释一下并帮助我找到解决方案吗?