How do I get the output of a websocket connection?

Viewed 95

How do I get the output of a websocket connection in python?

I have successfully created a websocket connection to a website, but I don't know how to take specific outputs of the last function in my code. Here is my code:

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()

I want to take the outputs of the function "ws.run_forever()", which are in a json format. How do I take these outputs and put them in for example a dictionary?

0 Answers
Related