Python3 socketio从on_message返回数据以在其他python函数中使用

问题描述

我可能走错了路,但是我正在尝试执行以下操作,但是令牌从未从on_message返回

import socketio

sio = socketio.Client()
token = ""

def on_message(data):
    token = data.get('token')
    token = str(token)
    return token

sio.connect('http://192.168.155.249')

sio.emit("postLogin",{"email":"[email protected]","password":"password"})
token = sio.on('user',on_message)

sio.emit("saveDocument",{"title":"","content":"asdfas","id":"2","token":token})

虽然我可以将saveDocument放到on_message中,但我还有其他地方需要使用令牌(稍后将使用Requests库将数据发布到其他地方)。初学者,我在python-socketio文档中看到了回调的提法,但是我不确定它们是否可以帮助我完成所要完成的工作。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)