tronikos / opower

A Python library for getting historical and forecasted usage/cost from utilities that use opower.com such as PG&E
Apache License 2.0
53 stars 49 forks source link

New login flow for Duquesne Light (DQE) breaks Opower integration #83

Open cisasteelersfan opened 3 weeks ago

cisasteelersfan commented 3 weeks ago

Hi there, I noticed (within the last few days) that Home Assistant wasn't updating my Duquesne Light Opower stats.

Full logs (from Home Assistant):

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/opower/opower.py", line 197, in async_login
    self.access_token = await self.utility.async_login(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/opower/utilities/duquesnelight.py", line 91, in async_login
    async with session.post(
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 1197, in __aenter__
    self._resp = await self._coro
                 ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client.py", line 696, in _request
    resp.raise_for_status()
  File "/usr/local/lib/python3.12/site-packages/aiohttp/client_reqrep.py", line 1070, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 404, message='Not Found', url=URL('https://www.duquesnelight.com/login/login')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/homeassistant/helpers/update_coordinator.py", line 312, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/homeassistant/components/opower/coordinator.py", line 81, in _async_update_data
    await self.api.async_login()
  File "/usr/local/lib/python3.12/site-packages/opower/opower.py", line 205, in async_login
    raise CannotConnect(err)
opower.exceptions.CannotConnect: 404, message='Not Found', url=URL('https://www.duquesnelight.com/login/login')

Indeed, I'm not able to access https://www.duquesnelight.com/login/login in the browser either.

From the Duquesne Light homepage, it appears login has moved to https://auth.duquesnelight.com/oauth/authorize/?client_id=33292caf-08ce-4631-a7a1-7bc3e30d318c&response_type=code&redirect_uri=https%3a%2f%2fduquesnelight.com%2fdlc%2flogin%3fredirectUrl%3d%252faccount-billing%252faccount-summary (concise, right?).

I saw that @swartzd was the original creator of this utility integration in #68. I poked around in the code, replacing all of the headers and payload with the new values that I copied from my Chrome network tools console, however I'm getting opower.exceptions.CannotConnect: 408, message='Request Timeout', url=URL('https://auth.duquesnelight.com/oauth/authorize?client_id=33292caf-08ce-4631-a7a1-7bc3e30d318c&response_type=code&redirect_uri=https://www.duquesnelight.com/dlc/login?redirectUrl%3D%252faccount-billing%252faccount-summary').

Would appreciate it if someone else could take a look. Thanks!!

swartzd commented 3 weeks ago

I will take a look at this within the next few days! I noticed this as well but had not yet had time to investigate.

swartzd commented 1 week ago

Just want to update: I have figured out the new login endpoint but I have yet to make the whole flow work again. Thanks for your patience

swartzd commented 1 week ago

I've got website login/authentication working but all further page access is getting blocked by incapsula/imperva. I have spent considerable time trying to make it work without success (not giving up but also do not have any light at the end of the tunnel)

pioto commented 1 week ago

Thanks for giving this a go. I had tried to write this integration myself a few months ago but their Incapsula/Imperva WAF was a problem then as well (it looks like you made some headway with additional headers to be more browser-y).

Doubtful, but in case anything I had tried helps you: https://github.com/tronikos/opower/compare/main...pioto:opower:duquesnelight