Websocket client not connecting in python

1k Views Asked by At

I have tried a code to collect information from binance, however when I run it the connection does not open and the output only shows "closed connection". Is this because of any firewall for visual studio code 2 or should I add any codes? Please show guidance, Thanks!

My code is shown below

import websocket

websocket.enableTrace(True)
SOCKET = "wss://stream.binance.com:9443/ws/btcusdt@kline_1m"

def on_open(ws):
    print('opened connection')

def on_close(ws):
    print('closed connection')

def on_message(ws, message):
    print('received message')

ws = websocket.WebSocketApp(SOCKET, on_open=on_open, on_close=on_close, on_message=on_message)
ws.run_forever()

My output is only closed connection as shown below.

closed connection
0

There are 0 best solutions below