From 468c63f69704a3664289456436d385d5a5abc95f Mon Sep 17 00:00:00 2001 From: Adem <34811741+aatikturk@users.noreply.github.com> Date: Fri, 23 Jun 2023 01:48:45 +0300 Subject: [PATCH 1/5] auth logger for clients added RpcVersion in auth loggers for both requests and events clients. removed the check in baseclient auth function and returned the whole response. --- obsws_python/baseclient.py | 2 +- obsws_python/events.py | 5 +++-- obsws_python/reqs.py | 5 +++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/obsws_python/baseclient.py b/obsws_python/baseclient.py index fedc517..abce10f 100644 --- a/obsws_python/baseclient.py +++ b/obsws_python/baseclient.py @@ -108,7 +108,7 @@ class ObsClient: self.ws.send(json.dumps(payload)) try: response = json.loads(self.ws.recv()) - return response["op"] == 2 + return response except json.decoder.JSONDecodeError: raise OBSSDKError("failed to identify client with the server") diff --git a/obsws_python/events.py b/obsws_python/events.py index 8b6b604..d002b58 100644 --- a/obsws_python/events.py +++ b/obsws_python/events.py @@ -27,8 +27,9 @@ class EventClient: defaultkwargs = {"subs": Subs.LOW_VOLUME} kwargs = defaultkwargs | kwargs self.base_client = ObsClient(**kwargs) - if self.base_client.authenticate(): - self.logger.info(f"Successfully identified {self} with the server") + auth_status = self.base_client.authenticate() + if auth_status: + self.logger.info(f"Successfully identified {self} with the server using rpcVersion:{auth_status['d']['negotiatedRpcVersion']}") self.callback = Callback() self.subscribe() diff --git a/obsws_python/reqs.py b/obsws_python/reqs.py index 4ff4544..c363ead 100644 --- a/obsws_python/reqs.py +++ b/obsws_python/reqs.py @@ -17,8 +17,9 @@ class ReqClient: def __init__(self, **kwargs): self.logger = logger.getChild(self.__class__.__name__) self.base_client = ObsClient(**kwargs) - if self.base_client.authenticate(): - self.logger.info(f"Successfully identified {self} with the server") + auth_status = self.base_client.authenticate() + if auth_status: + self.logger.info(f"Successfully identified {self} with the server using rpcVersion:{auth_status['d']['negotiatedRpcVersion']}") def __enter__(self): return self From 4ced7193df48b19ea6ef0a61f936a76354f0048e Mon Sep 17 00:00:00 2001 From: Adem <34811741+aatikturk@users.noreply.github.com> Date: Fri, 23 Jun 2023 01:53:02 +0300 Subject: [PATCH 2/5] patch bump --- obsws_python/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/obsws_python/version.py b/obsws_python/version.py index 0c46db4..10cd127 100644 --- a/obsws_python/version.py +++ b/obsws_python/version.py @@ -1 +1 @@ -version = "1.5.1" +version = "1.5.2" From 126e5cb0a4a85bae4c91da0c7e77e322a310c629 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Wed, 28 Jun 2023 17:56:29 +0100 Subject: [PATCH 3/5] raise OBSSDKError if auth reponse opcode != 2 --- obsws_python/baseclient.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/obsws_python/baseclient.py b/obsws_python/baseclient.py index abce10f..ca9ac1e 100644 --- a/obsws_python/baseclient.py +++ b/obsws_python/baseclient.py @@ -108,9 +108,15 @@ class ObsClient: self.ws.send(json.dumps(payload)) try: response = json.loads(self.ws.recv()) - return response + if response["op"] != 2: + raise OBSSDKError( + "failed to identify client with the server, expected response with OpCode 2 Identified" + ) + return response["d"] except json.decoder.JSONDecodeError: - raise OBSSDKError("failed to identify client with the server") + raise OBSSDKError( + "failed to identify client with the server, please check connection settings" + ) def req(self, req_type, req_data=None): payload = { From 5462c47b6544af371b145679a3c5ada23fc8507f Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Wed, 28 Jun 2023 17:56:56 +0100 Subject: [PATCH 4/5] log errors raised in authenticate() --- obsws_python/events.py | 13 +++++++++---- obsws_python/reqs.py | 11 ++++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/obsws_python/events.py b/obsws_python/events.py index d002b58..5ac828e 100644 --- a/obsws_python/events.py +++ b/obsws_python/events.py @@ -7,7 +7,7 @@ from websocket import WebSocketTimeoutException from .baseclient import ObsClient from .callback import Callback -from .error import OBSSDKTimeoutError +from .error import OBSSDKError, OBSSDKTimeoutError from .subs import Subs """ @@ -27,9 +27,14 @@ class EventClient: defaultkwargs = {"subs": Subs.LOW_VOLUME} kwargs = defaultkwargs | kwargs self.base_client = ObsClient(**kwargs) - auth_status = self.base_client.authenticate() - if auth_status: - self.logger.info(f"Successfully identified {self} with the server using rpcVersion:{auth_status['d']['negotiatedRpcVersion']}") + try: + success = self.base_client.authenticate() + self.logger.info( + f"Successfully identified {self} with the server using RPC version:{success['negotiatedRpcVersion']}" + ) + except OBSSDKError as e: + self.logger.error(f"{type(e).__name__}: {e}") + raise self.callback = Callback() self.subscribe() diff --git a/obsws_python/reqs.py b/obsws_python/reqs.py index c363ead..5037913 100644 --- a/obsws_python/reqs.py +++ b/obsws_python/reqs.py @@ -17,9 +17,14 @@ class ReqClient: def __init__(self, **kwargs): self.logger = logger.getChild(self.__class__.__name__) self.base_client = ObsClient(**kwargs) - auth_status = self.base_client.authenticate() - if auth_status: - self.logger.info(f"Successfully identified {self} with the server using rpcVersion:{auth_status['d']['negotiatedRpcVersion']}") + try: + success = self.base_client.authenticate() + self.logger.info( + f"Successfully identified {self} with the server using RPC version:{success['negotiatedRpcVersion']}" + ) + except OBSSDKError as e: + self.logger.error(f"{type(e).__name__}: {e}") + raise def __enter__(self): return self From 98b17b6749b0b2b734ab6fe347e9b8a33bc0b679 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Fri, 30 Jun 2023 22:44:50 +0100 Subject: [PATCH 5/5] add .python-version to .gitignore --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index 6918ff5..58ee456 100644 --- a/.gitignore +++ b/.gitignore @@ -45,6 +45,11 @@ env.bak/ venv.bak/ .hatch +# pyenv +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +.python-version + # Test/config quick.py config.toml