home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.64k stars 30.79k forks source link

Opower / Evergy fails on setup, reports unauthorized #97655

Closed cerebrate closed 1 year ago

cerebrate commented 1 year ago

The problem

On attempting to set up the Opower integration to use Evergy, while the setup completes, the integration reports "Failed setup, will retry". Retries are unsuccessful. On the surface, it looks like an authentication failure, with the following error reported in the logs:

2023-08-03 00:28:30.043 WARNING (MainThread) [homeassistant.config_entries] Config entry 'Evergy (amygray)' for opower integration not ready yet: 401, message='Unauthorized', url=URL('https://kcpk.opower.com/ei/edge/apis/multi-account-v1/cws/kcpk/customers?offset=0&batchSize=100&addressFilter='); Retrying in background

But repeated tests have confirmed that the username and password supplied are correct and function to access the Evergy web site.

What version of Home Assistant Core has the issue?

core-2023.8.0

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

opower

Link to integration documentation on our website

https://www.home-assistant.io/integrations/opower

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2023-08-03 00:28:30.043 WARNING (MainThread) [homeassistant.config_entries] Config entry 'Evergy (amygray)' for opower integration not ready yet: 401, message='Unauthorized', url=URL('https://kcpk.opower.com/ei/edge/apis/multi-account-v1/cws/kcpk/customers?offset=0&batchSize=100&addressFilter='); Retrying in background

Additional information

No response

home-assistant[bot] commented 1 year ago

Hey there @tronikos, mind taking a look at this issue as it has been labeled with an integration (opower) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `opower` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign opower` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


opower documentation opower source (message by IssueLinks)

suheilpurewal commented 1 year ago

Exact same issue here with evergy. Have tried both the HACS version and the official, both having the same error.

tboyce021 commented 1 year ago

Same issue here but running the demo from the python library via command line works fine.

Edit: Spoke too soon. 0.15 demo works but 0.18 demo gives 401 error.

tboyce021 commented 1 year ago

It seems Evergy doesn't like this change: https://github.com/tronikos/opower/commit/28a4efd3c1d336777b6a9916e5e88aa69c6a5988

hanley-development commented 1 year ago

2023-08-03 02:29:36.812 WARNING (MainThread) [homeassistant.config_entries] Config entry 'Evergy (USER)' for opower integration not ready yet: 401, message='Unauthorized', url=URL('https://kcpl.opower.com/ei/edge/apis/multi-account-v1/cws/kcpl/customers?offset=0&batchSize=100&addressFilter='); Retrying in background 2023-08-03 02:29:46.633 DEBUG (MainThread) [homeassistant.components.opower.coordinator] Finished fetching Opower data in 4.663 seconds (success: False) 2023-08-03 02:30:01.405 DEBUG (MainThread) [homeassistant.components.opower.coordinator] Finished fetching Opower data in 4.269 seconds (success: False) 2023-08-03 02:30:26.061 DEBUG (MainThread) [homeassistant.components.opower.coordinator] Finished fetching Opower data in 4.471 seconds (success: False)

tronikos commented 1 year ago

I asked the 2 Evergy contributors to take a look since it looks like my https://github.com/tronikos/opower/commit/28a4efd3c1d336777b6a9916e5e88aa69c6a5988 broke Evergy.

hanley-development commented 1 year ago

I asked the 2 Evergy contributors to take a look since it looks like my tronikos/opower@28a4efd broke Evergy.

Let us know if there is something you'd like us to test.

tboyce021 commented 1 year ago

Looking at the headers, it looks like the 'authorization' has an extra 'Bearer' in it that wasn't there in 0.0.16:

'authorization': 'Bearer Bearer XXXX'
tboyce021 commented 1 year ago

Indeed, removing 'Bearer' from this line fixes it: https://github.com/tronikos/opower/commit/28a4efd3c1d336777b6a9916e5e88aa69c6a5988#diff-7dce08179b97e85eeacb89007dc7c1052d06fbc7fa5d3108541a1f5d9a927925R390

tronikos commented 1 year ago

Thanks for catching it. I missed that. I'll modify line: opower_access_token = resp.headers["jwt"] to remote the Bearer prefix.