Skip to content

Commit 28b3a78

Browse files
committed
Fix SSL certificate error
1 parent d380d65 commit 28b3a78

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,10 @@ A Python Lighthouse Adapter
44

55
(README WIP; please consult pyghthouse/ph.py for usage information.)
66

7-
Example scripts can be found [here](examples)
7+
Example scripts can be found [here](examples)
8+
9+
## Troubeshooting
10+
11+
If you are experiencing errors regarding SSL certificates,
12+
instantiate Pyghthouse using the `ignore_ssl_cert=True`
13+
keyword argument.

pyghthouse/connection/wsconnector.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from threading import Thread, Lock
22
from websocket import WebSocketApp, setdefaulttimeout, ABNF
33
from msgpack import packb, unpackb
4+
from ssl import CERT_NONE
45

56

67
class WSConnector:
@@ -17,7 +18,7 @@ def __next__(self):
1718
def __iter__(self):
1819
return self
1920

20-
def __init__(self, username: str, token: str, address: str, on_msg=None):
21+
def __init__(self, username: str, token: str, address: str, on_msg=None, ignore_ssl_cert=False):
2122
self.username = username
2223
self.token = token
2324
self.address = address
@@ -26,6 +27,7 @@ def __init__(self, username: str, token: str, address: str, on_msg=None):
2627
self.lock = Lock()
2728
self.reid = self.REID()
2829
self.running = False
30+
self.ignore_ssl_cert = ignore_ssl_cert
2931
setdefaulttimeout(60)
3032

3133
def send(self, data):
@@ -38,7 +40,8 @@ def start(self):
3840
on_message=None if self.on_msg is None else self._handle_msg,
3941
on_open=self._ready, on_error=self._fail)
4042
self.lock.acquire()
41-
Thread(target=self.ws.run_forever).start()
43+
kwargs = {"sslopt": {"cert_reqs": CERT_NONE}} if self.ignore_ssl_cert else None
44+
Thread(target=self.ws.run_forever, kwargs=kwargs).start()
4245

4346
def _fail(self, ws, err):
4447
self.lock.release()

pyghthouse/ph.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ def run(self):
186186
self.parent.connector.send(self.parent.canvas.get_image_bytes())
187187

188188
def __init__(self, username: str, token: str, address: str = "wss://lighthouse.uni-kiel.de/websocket",
189-
frame_rate: float = 30.0, image_callback=None, verbosity=VerbosityLevel.WARN_ONCE):
189+
frame_rate: float = 30.0, image_callback=None, verbosity=VerbosityLevel.WARN_ONCE,
190+
ignore_ssl_cert=False):
190191
if frame_rate > 60.0 or frame_rate <= 0:
191192
raise ValueError("Frame rate must be greater than 0 and at most 60.")
192193
self.username = username
@@ -196,7 +197,8 @@ def __init__(self, username: str, token: str, address: str = "wss://lighthouse.u
196197
self.image_callback = image_callback
197198
self.canvas = PyghthouseCanvas()
198199
self.msg_handler = self.PHMessageHandler(verbosity)
199-
self.connector = WSConnector(username, token, address, on_msg=self.msg_handler.handle)
200+
self.connector = WSConnector(username, token, address, on_msg=self.msg_handler.handle,
201+
ignore_ssl_cert=ignore_ssl_cert)
200202
self.config_lock = Lock()
201203
self.ph_thread = None
202204
signal(SIGINT, self._handle_sigint)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setup(
77
name='pyghthouse',
8-
version='0.2.0',
8+
version='0.2.1',
99
packages=find_packages(where='.'),
1010
url='https://github.com/Musicted/pyghthouse',
1111
license='MIT',

0 commit comments

Comments
 (0)