WebSocket stopped working out of nowhere - [WinError 10060]

Hello,

I had a running script to stream price data from Binance-Api, but for some reason it just stopped working and now returns:

“[WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond”.

Made no changes to my script, internet, IP or anything - just stopped working and it is now impossible to reconnect.

Code;

from binance.client import Client
import config
import websocket

client = Client(config.API_KEY, config.API_SECRET)

info = client.get_margin_account()

print(info)

SOCKET = f’wss://stream.binance.com:9443/ws/ethusdt@kline_1h/’

def on_open(ws):

print(‘opened connection’)

def on_close(was):

print(‘closed connection’)

def on_error(ws, error):

print(error)

def on_message(ws, message):

print(‘received message’)

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

OUTPUT:

[WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

Thanks in advance for any help!

We don’t support 3rd party libs, but if you still run into issues when using https://github.com/binance/binance-connector-python, feel free to repost here.

Hi Aisling,

thanks for quick reply. I tried this example (https://github.com/binance/binance-connector-python/blob/d15eed8defa62d3243b074ff18be3f9f20b2ff4a/examples/websocket/spot/combined_streams.py) from the official library and received this error:

INFO:root:Connection with URL: wss://stream.binance.com:9443/ws/bnbusdt@bookTicker
INFO:root:Start to connect…
INFO:root:Connection with URL: wss://stream.binance.com:9443/stream?streams=bnbusdt@bookTicker/ethusdt@bookTicker
INFO:root:Start to connect…
ERROR:root:Can’t connect to server. Reason: [Failure instance: Traceback (failure with no frames): <class ‘twisted.internet.error.TCPTimedOutError’>: TCP connection timed out: 10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond…
]. Retrying: 1
INFO:root:Start to connect…
ERROR:root:Can’t connect to server. Reason: [Failure instance: Traceback (failure with no frames): <class ‘twisted.internet.error.TCPTimedOutError’>: TCP connection timed out: 10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond…
]. Retrying: 1
INFO:root:Start to connect…
DEBUG:root:closing ws connection

Any suggestion?

INFO:root:Connection with URL: wss://stream.binance.com:9443/ws
INFO:root:Start to connect…
ERROR:root:Can’t connect to server. Reason: [Failure instance: Traceback (failure with no frames): <class ‘twisted.internet.error.TCPTimedOutError’>: TCP connection timed out: 10060: 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。.
]. Retrying: 1
INFO:root:Start to connect…
DEBUG:root:closing ws connection

Please make sure that you are not trying to connect in a restricted country.

I’m having the same issue here.

Can’t connect to server. Reason: [Failure instance: Traceback (failure with no frames): <class ‘twisted.internet.error.TCPTimedOutError’>: TCP connection timed out: 10060: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond…
]. Retrying: 1

I’m using binance-connector-python.
But when I’m trying to connect using websocket gui client, Simple WebSocket Client - Chrome Web Store (google.com).
It run without any problem