之前使用的websocket偶有断线的问题,后来在网上找到使用长连接的方法,需要引入websocket-client库,在前面import websocket后执行下面代码
websocket.enableTrace(True)
ws = websocket.WebSocketApp("ws://www.xxxx.cn:7002/ws/channels/",
on_message = on_message,
on_error = on_error,
on_close = on_close)
ws.on_open = on_open
ws.run_forever(ping_interval=60,ping_timeout=5)
报错AttributeError: module 'websocket' has no attribute 'enableTrace'
网上都说使用pip3 install websocket-client就行,但是我使用后依然报这个错,怀疑是之前的包与现在的有冲突。
使用pip3 list发现我安装了好几个版本
于是pip3 uninstall 其它两个版本,重新运行没问题了