I want to respond to a flask request, but the response is to be received from a socketio callback event. I am able to receive the response to an independent function, but unable to fetch it from there this is my main file
@app.route("/api/<token>")
def recharge(token):
socket_connected_user_index = next((i for i, x in enumerate(clients) if x["name"] == token), None)
if socket_connected_user_index is not None:
user = clients[socket_connected_user_index]['name']
socket_id = clients[socket_connected_user_index]['id']
number = request.args['number']
amount = request.args['amount']
pin = request.args['pin']
api_key = token
recharge_data = dict(number=number,amount=amount,pin=pin,api_key=api_key)
def server_callback(data):
print('server call back >> ' , data)
new_data = data
return new_data
response_from_function = socketio.emit('recharge_request', {'data': recharge_data},to=socket_id,callback=server_callback)
return jsonify(response_from_function)
else:
return jsonify({"status":"User not connected"})
I am unable to access the variable "response_from_function"
response_from_function = socketio.emit('recharge_request', {'data': recharge_data},to=socket_id,callback=server_callback)
right now when i call "/api/?params" i get None as a response
I want to fetch the return value from the function "server_callback" and return that value to the user as a response to the request
Let me know if anyone has any idea Thanks