I have inherited a program that makes a websocket connection to a server, reads messages from a queue then closes:
print("Starting the retreiving process")
ws = websocket.WebSocketApp(ws_url,
header={'authorization':'Basic ' + auth},
on_message=on_message,
on_error=on_error,
on_close=on_close)
#if error exit
print("Connected to websocket")
ws.on_open = on_open
wst=threading.Thread(target=ws.run_forever)
print("Starting the retreiving process")
wst.start()
time.sleep(float(active_time))
ws.keep_running=False
wst.join()
This was working fine for us. However, I’ve had to amend the Thread line as follows, to stop the connection carrying out SSL certificate checks:
wst=threading.Thread(target=ws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE}))
The program now successfully makes a connection to the server but never closes.
I’ve tried explicitly closing the connection with ws.close(), but no luck.
Two questions:
- is this expected behaviour - i.e. does bypassing ssl certificate checks mean that the connection will not close?
- how can I force the connection to close (after active_time seconds)?