Python3 socketio returning data from on_message to use in other python functions

286 views Asked by At

I might be on the wrong path but I'm trying to do something like the following however the token never gets returned from 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})

While i could put my saveDocument emit inside on_message i have other places i need to use token (will be using Requests library to post the data elsewhere later). Beginner coder and i see mentions of callbacks in the python-socketio documentation however i'm not sure if they can help with what i'm trying to accomplish.

0

There are 0 answers