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
69.96k stars 29.04k forks source link

Opower 403 Forbidden with PSE #120894

Closed scyto closed 4 days ago

scyto commented 2 weeks ago

The problem

I haven't managed to get this integration working in many months - not sure what version it broke. I have tried removing it, waiting a couple of weeks to see if i was being rate limited or blacklisted in some way. That didn't fix it

Needs attention

Puget Sound Energy (PSE) (scyto1) No devices or entities Failed setup, will retry: 403, message='Forbidden', url=URL('https://pse.opower.com/ei/edge/apis/DataBrowser-v1/cws/cost/utilityAccount/redacted?aggregateType=bill&startDate=2024-04-30T00:00:00- 07:00&endDate=2024-07-01T00:00:00-07:00')

...

What version of Home Assistant Core has the issue?

core-2024.5.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Opower

Link to integration documentation on our website

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

Diagnostics information

home-assistant_opower_2024-07-01T00-39-29.048Z.log

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Not really anything useful
I have two PSE accounts on my one login if that matters, i see that the logs try only one account and fail

Additional information

i note the database has my configuration items from when it was working as the energy setup shows two pse_elec and two pse_gas entities - but these don't show up in entities....

i don't have an MFA

i tried the URL i saw in pse.py (https://www.pse.com/api/AccountSelector/GetContractAccountJson) after logging into PSE website and it enumerated all my accounts just fine.

image

Troubleshooting step 2 My recorder/history was using mariadb add-on, i reverted the recorder config to default to use SQLite (it had no statistics tables in it) and then i readded the integration like in some other issues, this didn't fix this issue, it did remove all the entries seen in the screenshot above

home-assistant[bot] commented 2 weeks 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. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


opower documentation opower source (message by IssueLinks)

indiealexh commented 2 weeks ago

Likely related to https://github.com/home-assistant/core/issues/120797

scyto commented 2 weeks ago

Likely related to #120797

thanks, i note in that they are getting

2024-06-28 20:29:01.613 ERROR (MainThread) [frontend.js.latest.202406101] Failed to format translation for key 'component.opower.config.step.reauth_confirm.title' in language 'en'. Error: The intl string context variable "name" was not provided to the string "Authentication expired for {name}"

i am not seeing these in my log - so maybe the same, maybe not? (or i need to up the logging level byond what enabling debug on the integration does?)

--edit-- no defintely not in my logs, i upped the logger to debug for all components - nothing like those errors

scyto commented 2 weeks ago

enabled more debugging....


2024-07-01 13:51:10.816 DEBUG (MainThread) [homeassistant.components.opower.coordinator] Finished fetching Opower data in 16.936 seconds (success: False)
2024-07-01 13:51:10.816 DEBUG (MainThread) [homeassistant.config_entries] Config entry 'Puget Sound Energy (PSE) (REDACTED-PSE-USERNAME)' for opower integration not ready yet: 403, message='Forbidden', url=URL('https://pse.opower.com/ei/edge/apis/DataBrowser-v1/cws/cost/utilityAccount/REDACTED-GUID?aggregateType=bill&endDate=2024-07-01T13:51:10.591887-07:00'); Retrying in 10 seconds
2024-07-01 13:51:10.817 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection] [140100078020080] REDACTED-NAME from 192.168.1.198 (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0): Sending b'{"id":42,"type":"event","event":[{"type":"updated","entry":{"entry_id":"01J1R106YMZ4RVKS8DFEAFPE33","domain":"opower","title":"Puget Sound Energy (PSE) (REDACTED-PSE-USERNAME)","source":"user","state":"setup_retry","supports_options":false,"supports_remove_device":false,"supports_unload":true,"supports_reconfigure":false,"pref_disable_new_entities":false,"pref_disable_polling":false,"disabled_by":null,"reason":"403, message=\'Forbidden\', url=URL(\'https://pse.opower.com/ei/edge/apis/DataBrowser-v1/cws/cost/utilityAccount/REDACTED-GUID?aggregateType=bill&endDate=2024-07-01T13:51:10.591887-07:00\')","error_reason_translation_key":null,"error_reason_translation_placeholders":null}}]}'
2024-07-01 13:51:10.827 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection] [140100078020080] REDACTED-NAME from 192.168.1.198 (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0): Received {'type': 'frontend/get_translations', 'language': 'en', 'category': 'config', 'integration': ['opower'], 'id': 53}
2024-07-01 13:51:10.827 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection] [140100078020080] REDACTED-NAME from 192.168.1.198 (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36 Edg/127.0.0.0): Sending b'{"id":53,"type":"result","success":true,"result":{"resources":{"component.opower.config.abort.already_configured":"Service is already configured","component.opower.config.abort.reauth_successful":"Re-authentication was successful","component.opower.config.error.cannot_connect":"Failed to connect","component.opower.config.error.invalid_auth":"Invalid authentication","component.opower.config.step.mfa.data.totp_secret":"TOTP Secret","component.opower.config.step.mfa.description":"The TOTP secret below is not one of the 6 digit time-based numeric codes. It is a string of around 16 characters containing the shared secret that enables your authenticator app to generate the correct time-based code at the appropriate time. See the documentation.","component.opower.config.step.reauth_confirm.data.password":"Password","component.opower.config.step.reauth_confirm.data.totp_secret":"TOTP Secret","component.opower.config.step.reauth_confirm.data.username":"Username","component.opower.config.step.reauth_confirm.title":"Authentication expired for {name}","component.opower.config.step.user.data.password":"Password","component.opower.config.step.user.data.totp_secret":"TOTP Secret (only for some utilities, see documentation)","component.opower.config.step.user.data.username":"Username","component.opower.config.step.user.data.utility":"Utility name"}}}'
bsrotten commented 1 week ago

Just noticed I started getting an error with pse.

Failed setup, will retry: 403, message='Forbidden', url=URL('https://pse.opower.com/ei/edge/apis/DataBrowser-v1/cws/cost/utilityAccount/1ed162d5-d223-11e3-ba8c-1b40f3043709?aggregateType=bill&startDate=2024-06-01T00:00:00-07:00&endDate=2024-07-05T00:00:00-07:00')

indiealexh commented 1 week ago

Just noticed I started getting an error with pse.

Failed setup, will retry: 403, message='Forbidden', url=URL('https://pse.opower.com/ei/edge/apis/DataBrowser-v1/cws/cost/utilityAccount/1ed162d5-d223-11e3-ba8c-1b40f3043709?aggregateType=bill&startDate=2024-06-01T00:00:00-07:00&endDate=2024-07-05T00:00:00-07:00')

My initial guess is that opower doesn't like people using the API without asking and made some sort of breaking change? But I am not sure how to test that theory without a lot of digging.

scyto commented 1 week ago

My initial guess is that opower doesn't like people using the API without asking and made some sort of breaking change? But I am not sure how to test that theory without a lot of digging.

this was my initial assumption before i did any research, i removed the integration for a few weeks assuming it was a non-permanent rate limit - that didn't help.

hmm i could try routing internet traffic from the VPN out of my other backup router and see if its IP based restriction...

scyto commented 1 week ago

Nope it's not IP blacklisting.

so either a change in protocol / blocked account or blocked in some other way now

Turner-Home commented 1 week ago

I also have this problem and have for several releases now. Completely deleted, used the SQLlite web interface to clean out Opower settings and still fails to setup correctly.

Home Assistant Yellow PoE edition. Core 2024.7.1 Supervisor 2024.06.2 Operating System 12.4 Frontend 20240705.0 Same errors as the OP.

sovamind commented 5 days ago

I've been having the same issue with Portland General Electric and Opower Integration for the last three weeks. I just tried to delete everything and set it up again but it still fails to initialize devices or entities.

403, message='Forbidden', url=URL('https://pgn.opower.com/ei/edge/apis/DataBrowser-v1/cws/cost/utilityAccount/be5fa8d2-SNIP-a7?aggregateType=bill&startDate=2024-05-14T00:00:00-07:00&endDate=2024-07-11T00:00:00-07:00')

tronikos commented 5 days ago

To everyone here, can you run the following and provide the output?

pip install opower
python -m opower

Do you have access to the energy dashboard at your utility website? If you do, the easiest will likely be to temporarily change your password and privately share with me the login information. You can reach out to me at discord, community forum, or Gmail. My username is tronikos in all of them.

indiealexh commented 5 days ago

To everyone here, can you run the following and provide the output?

pip install opower
python -m opower

Do you have access to the energy dashboard at your utility website? If you do, the easiest will likely be to temporarily change your password and privately share with me the login information. You can reach out to me at discord, community forum, or Gmail. My username is tronikos in all of them.

Mine is here: https://github.com/tronikos/opower/issues/84

scyto commented 5 days ago

mine is here, usernames and accounts redacted

alexb@BIGRIG:~$ python -m opower
Utility, one of ['swepco', 'portlandgeneral', 'coned', 'oru', 'peco', 'evergy', 'psoklahoma', 'delmarva', 'appalachianpower', 'bge', 'aeptexas', 'smud', 'duquesnelight', 'pge', 'aepohio', 'atlanticcityelectric', 'pse', 'indianamichiganpower', 'enmax', 'comed', 'kentuckypower', 'coautilities', 'scl', 'pepco']: pse
Username: REDACTED
Password:

Getting historical data: account= Account(customer=Customer(uuid='REDACTED'), uuid='REDACTED', utility_account_id='REDACTED', id='REDACTED', meter_type=<MeterType.ELEC: 'ELEC'>, read_resolution=<ReadResolution.QUARTER_HOUR: 'QUARTER_HOUR'>) aggregate_type= day start_date= 2024-07-03 22:36:19.958230 end_date= 2024-07-10 22:36:19.958242
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/home/alexb/.local/lib/python3.11/site-packages/opower/__main__.py", line 214, in <module>
    asyncio.run(_main())
  File "/usr/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/home/alexb/.local/lib/python3.11/site-packages/opower/__main__.py", line 166, in _main
    cost_data = await opower.async_get_cost_reads(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alexb/.local/lib/python3.11/site-packages/opower/opower.py", line 394, in async_get_cost_reads
    reads = await self._async_get_dated_data(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alexb/.local/lib/python3.11/site-packages/opower/opower.py", line 503, in _async_get_dated_data
    reads = await self._async_fetch(
            ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/alexb/.local/lib/python3.11/site-packages/opower/opower.py", line 566, in _async_fetch
    raise err
  File "/home/alexb/.local/lib/python3.11/site-packages/opower/opower.py", line 553, in _async_fetch
    async with self.session.get(
  File "/home/alexb/.local/lib/python3.11/site-packages/aiohttp/client.py", line 1197, in __aenter__
    self._resp = await self._coro
                 ^^^^^^^^^^^^^^^^
  File "/home/alexb/.local/lib/python3.11/site-packages/aiohttp/client.py", line 696, in _request
    resp.raise_for_status()
  File "/home/alexb/.local/lib/python3.11/site-packages/aiohttp/client_reqrep.py", line 1070, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 403, message='Forbidden', url=URL('https://pse.opower.com/ei/edge/apis/DataBrowser-v1/cws/cost/utilityAccount/REDACTED?aggregateType=day&startDate=2024-07-03T00:00:00-07:00&endDate=2024-07-11T00:00:00-07:00')
scyto commented 5 days ago

not sure what you mean by enegegy dashbaord, maybe this?

image
tronikos commented 5 days ago

The PG&E one is strange because I also have PG&E and it works fine. I'm afraid you are either on your own trying to fix this or privately share with me your login information to debug and fix.

scyto commented 5 days ago

@tronikos i pinged you on discord, that would be good place to exchange details

tronikos commented 4 days ago

This was regressed in the 2024.6 release. I have a fix that will hopefully make it in 2024.7.3