Unable to connect to Websocket address?

263 views Asked by At

I'm trying to connect over an websocket address but my script is trowing an error on data recovery.

import requests
from websocket import create_connection

def conWs():
    ws = create_connection('wss://olymptrade.com/ds/v3')
    #ws.send('[{"t":1,"e":105,"d":[{"source":"platform"}]}]')
    #ws.send('[{"t":2,"e":90,"uuid":"JR20G7HQ62P0DURZO6F"}]')

    print(ws.connected)

    while True:
        result = ws.recv()
        print ("Received '%s'" % result)

I was expecting it to connect and start to receive websocket data, but the script breaks on with the error below:

websocket._exceptions.WebSocketConnectionClosedException: Connection is already closed.
1

There are 1 answers

1
Scott Skiles On

Looks like you will need to use a different approach.

Short-lived one-off send-receive

This (your code above) is if you want to communicate a short message and disconnect immediately when done.

Take a look at the example for Long-lived connection in the docs and please let me know if these modifications work for you. Good luck!