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
65 stars 59 forks source link

403 Forbidden error - PG&E - HA #84

Closed indiealexh closed 4 months ago

indiealexh commented 4 months ago

This issue is related to https://github.com/home-assistant/core/issues/120797

Getting the following error when attempting to access data. (Censored UUIDs, IDs, Username and Passwords with asterisks)

$ python -m opower --utility pge --username ****** --password ******

Current bill forecast: Forecast(account=Account(customer=Customer(uuid='***'), uuid='***', ut
ility_account_id='***', id='***', meter_type=<MeterType.ELEC: 'ELEC'>, read_resolution=None), start_date=datetime.date(2024, 6, 17), end_date=dat
etime.date(2024, 7, 17), current_date=datetime.date(2024, 7, 1), unit_of_measure=<UnitOfMeasure.KWH: 'KWH'>, usage_to_date=792.0, cost_to_date=300.0, forecasted_usage=2086.0, forecasted_cost=870.0, typical_usage=2445.0, typical_cost=250.0)

Current bill forecast: Forecast(account=Account(customer=Customer(uuid='***'), uuid='***', ut
ility_account_id='***', id='***', meter_type=<MeterType.ELEC: 'ELEC'>, read_resolution=None), start_date=datetime.date(2024, 6, 18), end_date=dat
etime.date(2024, 7, 18), current_date=datetime.date(2024, 7, 1), unit_of_measure=<UnitOfMeasure.KWH: 'KWH'>, usage_to_date=9.0, cost_to_date=4.0, forecasted_usage=30.0, forecasted_cost=12.0, typical_usage=56.0, typical_cost=12.0)

Getting historical data: account= Account(customer=Customer(uuid='***'), uuid='***', utility_
account_id='***', id='***', meter_type=<MeterType.ELEC: 'ELEC'>, read_resolution=<ReadResolution.HOUR: 'HOUR'>) aggregate_type= day start_date= 2024-06-24 16:03:16.714456 end_date= 2024-07-01 16:03:16.714456
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\indie\PycharmProjects\opower\.venv\Lib\site-packages\opower\__main__.py", line 214, in <module>
    asyncio.run(_main())
  File "C:\Python311\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\indie\PycharmProjects\opower\.venv\Lib\site-packages\opower\__main__.py", line 166, in _main
    cost_data = await opower.async_get_cost_reads(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\indie\PycharmProjects\opower\.venv\Lib\site-packages\opower\opower.py", line 394, in async_get_cost_reads
    reads = await self._async_get_dated_data(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\indie\PycharmProjects\opower\.venv\Lib\site-packages\opower\opower.py", line 503, in _async_get_dated_data
    reads = await self._async_fetch(
            ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\indie\PycharmProjects\opower\.venv\Lib\site-packages\opower\opower.py", line 566, in _async_fetch
    raise err
  File "C:\Users\indie\PycharmProjects\opower\.venv\Lib\site-packages\opower\opower.py", line 553, in _async_fetch
    async with self.session.get(
  File "C:\Users\indie\PycharmProjects\opower\.venv\Lib\site-packages\aiohttp\client.py", line 1197, in __aenter__
    self._resp = await self._coro
                 ^^^^^^^^^^^^^^^^
  File "C:\Users\indie\PycharmProjects\opower\.venv\Lib\site-packages\aiohttp\client.py", line 696, in _request
    resp.raise_for_status()
  File "C:\Users\indie\PycharmProjects\opower\.venv\Lib\site-packages\aiohttp\client_reqrep.py", line 1070, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 403, message='Forbidden', url=URL('https://pge.opower.com/ei/edge/apis/DataBrowser-v1/cws/cost/utilityAccount/***?aggregateType=day&startDate=2024-06-24T00:00:00-07:00&endDate=2024-07-02T00:00:00-07:00')
tronikos commented 4 months ago

Fixed in v0.5.1 I'll bump the version on HA