This is a known issue with pyOpenSSL package on windows. The bug is that twisted does not includes a trust root sets of its own. The workaround here is by using certifi and setting the correct environment variable for twisted manually. This is the API documentation about the environment variable(SSL_CERT_FILE) to set for twisted.
If you run the file from cmd,
pip install certifi
for /f %i in ('python -m certifi') do set SSL_CERT_FILE=%i
python example.py
if you run the file on an IDE e.g pycharm,
pip install certifi
Get the file path of cacert.pem by running python -m certifi
Copy the file path of cacert.pem and set the Environment Variables for SSL_CERT_FILE. These are the steps to setup environment variable on windows.
Restart IDE and run the websocket example
P.S: These steps were done by using PyCharm and PyCharm imports system environment variables automatically when running the project. If you are using other IDEs, please ensure that the project runs with the system’s environment variables.