From 2cb965a9824d313d6fac7a2cf3c9d3ce75f94c13 Mon Sep 17 00:00:00 2001 From: ehendrix23 Date: Mon, 25 Nov 2024 19:46:49 -0700 Subject: [PATCH] fix: UnboundLocalError when both websession and api_proxy_cert provided Fix for when both websession and api_proxy_cert are provided. --- teslajsonpy/controller.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/teslajsonpy/controller.py b/teslajsonpy/controller.py index 8ed080a..8c0c868 100644 --- a/teslajsonpy/controller.py +++ b/teslajsonpy/controller.py @@ -140,14 +140,14 @@ def __init__( ssl_context = ssl.create_default_context() websession = httpx.AsyncClient(timeout=60, verify=ssl_context) - if api_proxy_cert: - # Loading custom SSL certificate for proxy does blocking I/O. - # It is recommended to instead pass an httpx.AsyncClient that - # already has an SSL context with the custom certificate loaded. - try: - ssl_context.load_verify_locations(api_proxy_cert) - except (FileNotFoundError, ssl.SSLError): - _LOGGER.warning("Unable to load custom SSL certificate from %s", api_proxy_cert) + if api_proxy_cert: + # Loading custom SSL certificate for proxy does blocking I/O. + # It is recommended to instead pass an httpx.AsyncClient that + # already has an SSL context with the custom certificate loaded. + try: + ssl_context.load_verify_locations(api_proxy_cert) + except (FileNotFoundError, ssl.SSLError): + _LOGGER.warning("Unable to load custom SSL certificate from %s", api_proxy_cert) self.__connection = Connection( websession=websession,