I'm using Python Socket.IO server and client and websocket client for python to create a tunnel from my Raspberry Pi to my server on AWS.
My tunnel works great, apart from when the server disconnects due to an error. When this happens, this is the exception I get on my Raspberry Pi.
I would like to catch thsocket2is exception and perform some actions when it occurs, but I failed to catch it so far.
I have tried the following, with no success:
- add on_error and on_close methods on websocket.WebSocketApp()
- surround websocket.WebSocketApp.run_forever() with a try-catch
- surround socketio.Client.connect() with a try-catch
- check for socketio.Client.connect() return value
My exception:
Exception in thread Thread-6:
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/pi/.local/lib/python3.5/site-packages/socketio/client.py", line 439, in _handle_reconnect
socketio_path=self.socketio_path)
File "/home/pi/.local/lib/python3.5/site-packages/socketio/client.py", line 208, in connect
engineio_path=socketio_path)
File "/home/pi/.local/lib/python3.5/site-packages/engineio/client.py", line 166, in connect
url, headers, engineio_path)
File "/home/pi/.local/lib/python3.5/site-packages/engineio/client.py", line 303, in _connect_polling
if self._connect_websocket(url, headers, engineio_path):
File "/home/pi/.local/lib/python3.5/site-packages/engineio/client.py", line 333, in _connect_websocket
websocket_url + self._get_url_timestamp(), header=headers)
File "/home/pi/.local/lib/python3.5/site-packages/websocket/_core.py", line 511, in create_connection
websock.connect(url, **options)
File "/home/pi/.local/lib/python3.5/site-packages/websocket/_core.py", line 223, in connect
self.handshake_response = handshake(self.sock, *addrs, **options)
File "/home/pi/.local/lib/python3.5/site-packages/websocket/_handshake.py", line 79, in handshake
status, resp = _get_resp_headers(sock)
File "/home/pi/.local/lib/python3.5/site-packages/websocket/_handshake.py", line 152, in _get_resp_headers
raise WebSocketBadStatusException("Handshake status %d %s", status, status_message)
websocket._exceptions.WebSocketBadStatusException: Handshake status 502 Bad Gateway