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

0.0.29 demo.py fails with 401 unauthorized for ConEd fetching customers #39

Closed rct closed 1 year ago

rct commented 1 year ago

I pulled in the latest from your repo to get 0.0.29 changes. Now ConEd login fails with 401 unauthorized while trying to fetch /ei/edge/apis/multi-account-v1/cws/cned/customers

I think if it was a real login problem, I should have gotten the error earlier?

I'm still trying to dig into this. I did check that I can still log in via the web UI.

If I checkout v0.0.28, I don't run into this problem.


DEBUG:/mnt/s2/home/rct/proj/coned/tronikos/opower/src/opower/opower.py:Fetching: https://cned.opower.com/ei/edge/apis/multi-account-v1/cws/cned/customers?offset=0&batchSize=100&addressFilter=
Traceback (most recent call last):
  File "/mnt/s2/home/rct/proj/coned/tronikos/opower/src/demo.py", line 162, 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 81, in _main
    for forecast in await opower.async_get_forecast():
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/s2/home/rct/proj/coned/tronikos/opower/src/opower/opower.py", line 237, in async_get_forecast
    for customer in await self._async_get_customers():
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/mnt/s2/home/rct/proj/coned/tronikos/opower/src/opower/opower.py", line 298, in _async_get_customers
    async with self.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: 401, message='Unauthorized', url=URL('https://cned.opower.com/ei/edge/apis/multi-account-v1/cws/cned/customers?offset=0&batchSize=100&addressFilter=')
rct commented 1 year ago

The problem occurs with commit d983dca... mypy

tronikos commented 1 year ago

Can you try changing line 122 from return await resp.text() back to return await resp.json()?

tronikos commented 1 year ago

Can you actually try return str(await resp.json())?

tronikos commented 1 year ago

I just committed this change. Please try again

rct commented 1 year ago

Ok, 38ae5a1718822ad89ee964548c422208347f5865 fixed this.