Skip to content

Commit

Permalink
fix: resolved issue with sc_token
Browse files Browse the repository at this point in the history
  • Loading branch information
Lash-L committed Feb 8, 2023
1 parent 501ba1a commit 9138c10
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/southern_company_api/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from typing import List

import aiohttp as aiohttp
from aiohttp import ContentTypeError

from southern_company_api.account import Account

Expand Down Expand Up @@ -80,9 +81,15 @@ async def _get_sc_web_token(self) -> str:
async with session.post(
"https://webauth.southernco.com/api/login", json=data, headers=headers
) as response:
connection = await response.json()
if connection["statusCode"] == 500:
raise InvalidLogin()
print(response.status)
if response.status != 200:
raise CantReachSouthernCompany()
try:
connection = await response.json()
except ContentTypeError as err:
raise InvalidLogin from err
if connection["statusCode"] == 500:
raise InvalidLogin()
sc_regex = re.compile(r"NAME='ScWebToken' value='(\S+.\S+.\S+)'", re.IGNORECASE)
sc_data = sc_regex.search(connection["data"]["html"])
if sc_data and sc_data.group(1):
Expand Down

0 comments on commit 9138c10

Please sign in to comment.