Created
August 20, 2019 16:40
-
-
Save ryanquinlan/09f938186f3465c1b7e8e2bd131fed37 to your computer and use it in GitHub Desktop.
Cisco Meeting Server Events Websocket using Python websocket-client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import websocket | |
# Get auth token via POST to /api/v1/authTokens | |
# Use returned token to open a websocket connection to wss://host:port/events/v1 | |
# Token is passed as the URL parameter authToken | |
try: | |
self.logger.info("Getting auth token ...") | |
api_conn = api.ApiConnection(self.address, self.username, self.password, port=self.port) | |
response = api_conn.doPost("authTokens", {}) | |
auth_token = response.headers["X-Cisco-CMS-Auth-Token"] | |
url = "wss://%s:%s/events/v1?authToken=%s" % (self.address, self.port, auth_token) | |
self.logger.info("Opening websocket %s" % url) | |
self.ws = websocket.WebSocketApp(url, | |
on_error=self.onError, | |
on_message=self.processWebSocketMessage, | |
on_open=self.onOpen, | |
on_close=self.processClose) | |
with self._lock: | |
self.running = True | |
self.ws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE, "check_hostname": False}) | |
except Exception: | |
sys.excepthook(*sys.exc_info()) | |
raise | |
finally: | |
with self._lock: | |
self.running = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment