Skip to content
Advertisement

Python websocket closes after few seconds

I am try subscribe API http://developers.xstore.pro/documentation/

Process how I am doing it.

  1. Login (Ok)

  2. Subscribe some command (Ok)

  3. The data starts coming in (Ok)

  4. After few second (cca 20s) (Fail) on:

      File "/Users/luboshajek/.pyenv/versions/3.10.5/lib/python3.10/site-packages/websocket/_socket.py", line 122, in recv
    raise WebSocketConnectionClosedException( websocket._exceptions.WebSocketConnectionClosedException: Connection to remote host was lost.
    

Python or API closes connection :(

inicialize socket:

def inicialize(url):
   ws = websocket.WebSocket()
   response = ws.connect(url, receive_limit_ms=1000*3600)
   return ws

Every 5s I am sending following ping

def ping(): 
  print("Sending ping")
  ws.send(json.dumps({
        "command": "ping",
        "streamSessionId": sessionId
  }))

There is a way to open new connection but this approach it’s not optimal.

Advertisement

Answer

I probably violated some of validation rules or I worked with api with the wrong way.

Anyway I just use library xapi-node for nodejs and one of the wrapper for other languages.

It solve all my problems.

I hope that this will be helpful for somebody in future.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement