python - 如何获得 websocket 连接的输出?
问题描述
如何在 python 中获取 websocket 连接的输出?
我已成功创建到网站的 websocket 连接,但我不知道如何获取代码中最后一个函数的特定输出。这是我的代码:
def on_open(ws):
authentication = {
'action': 'authenticate',
'data': {'key': ''}
}
ws.send(json.dumps(authentication))
listen = {'action': 'listen', 'data': {'streams': ['SomeName']}}
ws.send(json.dumps(listen))
socket = 'SomeWebsite'
ws = websocket.WebSocketApp(socket, on_open)
ws.run_forever()
我想获取函数“ws.run_forever()”的输出,它是 json 格式的。如何获取这些输出并将它们放入例如字典中?
解决方案
推荐阅读
- javascript - 使用可加载库的 SSR React 应用程序,在主路由的服务器上间歇性地抛出“无法将未定义或 null 转换为对象”错误
- python - 如何用指定的方法抽象基类?
- python - python 列中重复波斯语单词的计数
- java - 尽管有flush(),但“分离的实体传递给坚持”
- php - 一旦满足某个自定义时间,如何更新表中的某个值 CRON JOB - PHP
- java - 带注释发现模式的 CDI 1.1 不适用于 Weblogic 12.2
- swift - 如何快速将图像居中到它位于上方的图像的中心
- ios - AudioPlayers 不适用于 iOS | 颤振插件
- r - 列名中的 Unicode
- python - 从 100x100 的 pytorch 张量中获取 10x10 的补丁,其中圆环样式环绕边界