Skip to content

Commit c9e7ea0

Browse files
committed
Allow not verifying SSL (opt-in)
1 parent 7a4078e commit c9e7ea0

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

alphaess/alphaess.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def __init__(
2020
appSecret,
2121
session: aiohttp.ClientSession | None = None,
2222
timeout: int = 30,
23-
ipaddress=None
23+
ipaddress=None,
24+
verify_ssl=True
2425
) -> None:
2526
"""Initialize."""
2627
self.appID = appID
@@ -33,6 +34,7 @@ def __init__(
3334
self._created_session = not session
3435
self.timeout = timeout
3536
self.ipaddress = ipaddress
37+
self.verify_ssl = verify_ssl
3638

3739
async def close(self) -> None:
3840
"""Close the AlphaESS API client."""
@@ -344,7 +346,8 @@ async def api_get(self, path, json=None) -> Optional(list):
344346
path,
345347
headers=headers,
346348
json=json,
347-
raise_for_status=True
349+
raise_for_status=True,
350+
ssl=self.verify_ssl
348351
) as response:
349352

350353
if response.status == 200:
@@ -375,7 +378,8 @@ async def api_post(self, path, json) -> Optional(dict):
375378
response = await self.session.post(
376379
path,
377380
headers=headers,
378-
json=json
381+
json=json,
382+
ssl=self.verify_ssl
379383
)
380384

381385
response.raise_for_status()

apitest.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import asyncio
22
import logging
33
import sys
4+
from enum import verify
5+
46
from alphaess.alphaess import alphaess
57
from datetime import date, timedelta
68

79
if len(sys.argv) != 3:
810
appID = input("AppID: ")
911
appSecret = input("AppSecret: ")
1012
IPAddress = input("IP Address (blank if not using): ") or None
13+
verify_ssl = input("Verify SSL? (Y/N, default Y): ").strip().upper() != "N"
1114
else:
1215
appID = sys.argv[1]
1316
appSecret = sys.argv[2]
1417
IPAddress = sys.argv[3]
18+
verify_ssl = True
1519

1620
logger = logging.getLogger('')
1721
logger.setLevel(logging.DEBUG)
@@ -28,7 +32,7 @@
2832
async def main():
2933
logger.debug("instantiating Alpha ESS Client")
3034
try:
31-
client: alphaess = alphaess(appID, appSecret, ipaddress=IPAddress)
35+
client: alphaess = alphaess(appID, appSecret, ipaddress=IPAddress, verify_ssl=verify_ssl)
3236
ESSList = await client.getESSList()
3337
for unit in ESSList:
3438
if "sysSn" in unit:

0 commit comments

Comments
 (0)