From 601fadcaab599444a5497cc7ba5c4be6a92bb9e7 Mon Sep 17 00:00:00 2001 From: Ryan Sears Date: Fri, 20 Dec 2019 00:01:51 -0500 Subject: [PATCH] Update websocket-client and add ping every 15s --- certstream/core.py | 12 ++++++------ requirements.txt | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/certstream/core.py b/certstream/core.py index e368500..d590413 100644 --- a/certstream/core.py +++ b/certstream/core.py @@ -27,12 +27,12 @@ def __init__(self, message_callback, url, skip_heartbeats=True, on_open=None, on on_error=self._on_error, ) - def _on_open(self, instance): + def _on_open(self): certstream_logger.info("Connection established to CertStream! Listening for events...") if self.on_open_handler: - self.on_open_handler(instance) + self.on_open_handler() - def _on_message(self, _, message): + def _on_message(self, message): frame = json.loads(message) if frame.get('message_type', None) == "heartbeat" and self.skip_heartbeats: @@ -40,18 +40,18 @@ def _on_message(self, _, message): self.message_callback(frame, self._context) - def _on_error(self, instance, ex): + def _on_error(self, ex): if type(ex) == KeyboardInterrupt: raise if self.on_error_handler: - self.on_error_handler(instance, ex) + self.on_error_handler(ex) certstream_logger.error("Error connecting to CertStream - {} - Sleeping for a few seconds and trying again...".format(ex)) def listen_for_events(message_callback, url, skip_heartbeats=True, setup_logger=True, on_open=None, on_error=None, **kwargs): try: while True: c = CertStreamClient(message_callback, url, skip_heartbeats=skip_heartbeats, on_open=on_open, on_error=on_error) - c.run_forever(**kwargs) + c.run_forever(ping_interval=15, **kwargs) time.sleep(5) except KeyboardInterrupt: certstream_logger.info("Kill command received, exiting!!") diff --git a/requirements.txt b/requirements.txt index e1bcd3a..dcfd3cd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -websocket-client==0.48.0 +websocket-client>=0.56.0 termcolor \ No newline at end of file