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
61 stars 55 forks source link

ConEd 500 Error on GetOpowerToken since account changes. #47

Closed rct closed 11 months ago

rct commented 11 months ago

As mentioned in https://github.com/home-assistant/core/issues/101829, ConEd made a number of changes to their systems around 2023-10-06. Since then for me I'm getting an error 500 response from the GetOpowerToken request.

Running demo.py using tronikos/main, I'm getting:

Traceback (most recent call last):
  File "/mnt/s2/home/rct/proj/coned/tronikos/opower/src/opower/opower.py", line 193, in async_login
    self.access_token = await self.utility.async_login(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/s2/home/rct/proj/coned/tronikos/opower/src/opower/utilities/coned.py", line 129, in async_login
    async with session.get(
  File "/srv/pyvenvs/opower/lib/python3.11/site-packages/aiohttp/client.py", line 1141, in __aenter__
    self._resp = await self._coro
                 ^^^^^^^^^^^^^^^^
  File "/srv/pyvenvs/opower/lib/python3.11/site-packages/aiohttp/client.py", line 643, in _request
    resp.raise_for_status()
  File "/srv/pyvenvs/opower/lib/python3.11/site-packages/aiohttp/client_reqrep.py", line 1005, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 500, message='Internal Server Error', url=URL('https://www.coned.com/sitecore/api/ssc/ConEd-Cms-Services-Controllers-Opower/OpowerService/0/GetOPowerToken')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/mnt/s2/home/rct/proj/coned/tronikos/opower/src/./demo.py", line 170, in <module>
    asyncio.run(_main())
  File "/opt/anaconda/anaconda3/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/opt/anaconda/anaconda3/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda/anaconda3/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/mnt/s2/home/rct/proj/coned/tronikos/opower/src/./demo.py", line 86, in _main
    await opower.async_login()
  File "/mnt/s2/home/rct/proj/coned/tronikos/opower/src/opower/opower.py", line 201, in async_login
    raise CannotConnect(err)
opower.exceptions.CannotConnect: 500, message='Internal Server Error', url=URL('https://www.coned.com/sitecore/api/ssc/ConEd-Cms-Services-Controllers-Opower/OpowerService/0/GetOPowerToken')

@Sebmaster - Is it working for you? Any ideas?

BEFH commented 11 months ago

I am no longer getting a TOTP error. In fact, no errors at all show up in my HA log, even when in log level info. When I run demo.py I get the same 500 exception as here.

rct commented 11 months ago

I am no longer getting a TOTP error. In fact, no errors at all show up in my HA log, even when in log level info. When I run demo.py I get the same 500 exception as here.

@BEFH - I believe if you are getting the same exception, for the same URL above with demo, you're likely to the point generating the TOTP token correctly. Unfortunately until what's changed with ConEd has been figured out, you're stuck at the same point as the rest of us.

tronikos commented 11 months ago

Does the energy dashboard on your utility website still work? In your browser developer tools > network tab do you still see a request to the GetOpowerToken endpoint? Is it at the same URL?

askjano commented 11 months ago

i see this in the general inspector. data-service-url="/en/accounts-billing/my-account/energy-use/energy-usage-types/energy-usage-residential" data-token-service-url-opower-v2="/sitecore/api/ssc/ConEd-Cms-Services-Controllers-Opower/OpowerService/0/GetOPowerToken" data-redirect-url-opower-v2="/sitecore/api/ssc/ConEd-Cms-Services-Controllers-Opower/OpowerService/0/GetOPowerRedirectUrl" data-module-started="true">

i have removed a bunch of the syntax since i dont know if it is something that shouldnt be published publicly.

in the network tab i see

https://www.coned.com/sitecore/api/ssc/ConEd-Cms-Services-Controllers-Opower/OpowerService/0/GetOPowerToken

rvsit commented 11 months ago

Also not working for me, same error. I did some testing on the headers and it seems that next to the Cookie header the Referer header also needs to be present. If it is not it will give a 500 error.

Specifically Referer: https://www.coned.com/

tronikos commented 11 months ago

Thanks @rvsit for fixing!