代码如下
import websocket
import json
def on_open(ws):
print(“connected”)
try:
subscribe = {“method”: “SUBSCRIBE”, “params”: [“btcusdt@kline_5m”], “id”: 1}
ws.send(json.dumps(subscribe))
except Exception as e:
print(e)
def on_message(ws, message):
data = json.loads(message)
print(data)
def on_error(ws, error):
print(error)
url = “wss://stream.binance.com:9443/ws”
ws = websocket.WebSocketApp(url, on_open=on_open, on_message=on_message, on_error=on_error)
while True:
try:
ws.run_forever()
except Exception as e:
print(e)
报错的是[WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。
我在大陆,使用vpn连接的,请问是这个的原因吗?