I've received the following error in my script on Websocket whilst trying to stream.
raise WebSocketConnectionClosedException("socket is already closed.") websocket._exceptions.WebSocketConnectionClosedException: socket is already closed.
I tried to code an exception to catch it and restart the websocket:
except WebSocketConnectionClosedException as e:
ws = opensocket()
websocket_open = True
data = "WebSocketConnectionClosedException trying to restart stream"
send_email(data,recipient)
print(e)
However, when I run it now, I get the following error:
Traceback (most recent call last): File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.3.3\helpers\pydev\pydevd.py", line 1668, in main() File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.3.3\helpers\pydev\pydevd.py", line 1662, in main globals = debugger.run(setup['file'], None, None, is_module) File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.3.3\helpers\pydev\pydevd.py", line 1072, in run pydev_imports.execfile(file, globals, locals) # execute the script File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.3.3\helpers\pydev_pydev_imps_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "C:/Users/Bev/Documents/python_work/bot/l_stream2_3.py", line 1117, in except WebSocketConnectionClosedException as e: NameError: name 'WebSocketConnectionClosedException' is not defined
Question 1 : How do i define the error in order for the exception to catch the error
Question 2: Are there perhaps a better way to restart the socket if the host closes the connection, or if the stream dies?