coinbasepro-python
coinbasepro-python copied to clipboard
No handling of WebSocketBadStatusException
When keeping a websocket connection open, I sometimes received the following error:
Traceback (most recent call last):
File "C:\Python36\Lib\threading.py", line 916, in _bootstrap_inner
self.run()
File "C:\Python36\Lib\threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "C:\Users\Matthew\Envs\arbitrage\lib\site-packages\gdax-1.0.6-py3.6.egg\gdax\websocket_client.py", line 40, in _go
self._connect()
File "C:\Users\Matthew\Envs\arbitrage\lib\site-packages\gdax-1.0.6-py3.6.egg\gdax\websocket_client.py", line 68, in _connect
self.ws = create_connection(self.url)
File "C:\Users\Matthew\Envs\arbitrage\lib\site-packages\websocket\_core.py", line 487, in create_connection
websock.connect(url, **options)
File "C:\Users\Matthew\Envs\arbitrage\lib\site-packages\websocket\_core.py", line 214, in connect
self.handshake_response = handshake(self.sock, *addrs, **options)
File "C:\Users\Matthew\Envs\arbitrage\lib\site-packages\websocket\_handshake.py", line 65, in handshake
status, resp = _get_resp_headers(sock)
File "C:\Users\Matthew\Envs\arbitrage\lib\site-packages\websocket\_handshake.py", line 122, in _get_resp_headers
raise WebSocketBadStatusException("Handshake status %d", status)
websocket._exceptions.WebSocketBadStatusException: Handshake status 429
This error was raised every 5-10 minutes or so. I fixed this by simply adding this in _connect():
try:
self.ws = create_connection(self.url)
except Exception as e:
self.on_error(e)
I'm not sure where the problem came from or if this is how it should behave. Is this how you want to handle it?
I'm getting a similar error.
Traceback (most recent call last):
File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
self.run()
File "/usr/lib/python3.5/threading.py", line 862, in run
self._target(*self._args, **self._kwargs)
File "/home/mike/.virtualenvs/gdax-trader/src/gdax/gdax/websocket_client.py", line 40, in _go
self._connect()
File "/home/mike/.virtualenvs/gdax-trader/src/gdax/gdax/websocket_client.py", line 68, in _connect
self.ws = create_connection(self.url)
File "/home/mike/.virtualenvs/gdax-trader/lib/python3.5/site-packages/websocket/_core.py", line 487, in create_connection
websock.connect(url, **options)
File "/home/mike/.virtualenvs/gdax-trader/lib/python3.5/site-packages/websocket/_core.py", line 214, in connect
self.handshake_response = handshake(self.sock, *addrs, **options)
File "/home/mike/.virtualenvs/gdax-trader/lib/python3.5/site-packages/websocket/_handshake.py", line 65, in handshake
status, resp = _get_resp_headers(sock)
File "/home/mike/.virtualenvs/gdax-trader/lib/python3.5/site-packages/websocket/_handshake.py", line 122, in _get_resp_headers
raise WebSocketBadStatusException("Handshake status %d", status)
websocket._exceptions.WebSocketBadStatusException: Handshake status 520
Looks like websocket-client throws an exception unless it gets a successful handshake, so this code should probably be guarded. Want to submit a PR with your change?
Sorry for the delay. I don't have time to do this for a few months; feel free to patch it when you can. Thanks.