Skip to content

Commit

Permalink
Merge pull request #7 from akoebbe/evergy
Browse files Browse the repository at this point in the history
Fix exception handling during evergy login
  • Loading branch information
tronikos authored Jul 13, 2023
2 parents c200598 + 01a357c commit e4fa5b4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/opower/utilities/evergy.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,15 @@ async def async_login(
"https://www.evergy.com/log-in",
data=login_payload,
allow_redirects=False,
raise_for_status=False,
) as resp:
# The response status will be 302 regardless of success, the redirect will tell us if we're logged in
if resp.headers["location"] != "/ma/my-account/account-summary":
raise InvalidAuth("Login failed")
# The response status will be 500 if verification token did not work
if resp.status == 500:
raise InvalidAuth("Login verification token failed")

# Counterintuitively, if we get a 200 back, that means the login failed
if resp.status == 200:
raise InvalidAuth("Username and password failed")

opower_access_token = None

Expand Down

0 comments on commit e4fa5b4

Please sign in to comment.