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

pse "AssertionError: Failed to parse __RequestVerificationToken" #40

Closed fallenpegasus closed 10 months ago

fallenpegasus commented 10 months ago

PSE is failing with ""AssertionError: Failed to parse __RequestVerificationToken""

Linux ip-172-30-3-187 5.10.0-20-cloud-arm64 #1 SMP Debian 5.10.158-2 (2022-12-13) aarch64 GNU/Linux

(.venv) admin@ip-172-30-3-187:~/opower$ cat /etc/os-release PRETTY_NAME="Debian GNU/Linux 11 (bullseye)" NAME="Debian GNU/Linux" VERSION_ID="11" VERSION="11 (bullseye)" VERSION_CODENAME=bullseye ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/"

(.venv) admin@ip-172-30-3-187:~/opower$ python -V Python 3.9.2

(.venv) admin@ip-172-30-3-187:~/opower$ python src/demo.py --verbose --utility pse --username murasakijou Password: Traceback (most recent call last): File "/home/admin/opower/src/demo.py", line 162, in asyncio.run(_main()) File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete return future.result() File "/home/admin/opower/src/demo.py", line 80, in _main await opower.async_login() File "/home/admin/opower/src/opower/opower.py", line 202, in async_login self.access_token = await self.utility.async_login( File "/home/admin/opower/src/opower/utilities/pse.py", line 96, in async_login assert ( AssertionError: Failed to parse __RequestVerificationToken

I would post more logs if I knew how. I did set DEBUG_LOG_RESPONSE = True

tronikos commented 10 months ago

Your exception confirms it's the 2nd login at https://github.com/tronikos/opower/blob/main/src/demo.py#L78-L80 that causes this.

Can you try adding the following code at the very beginning of async_login right after this line at https://github.com/tronikos/opower/blob/main/src/opower/utilities/pse.py#L86 ?

        session.cookie_jar.clear(lambda cookie: cookie["domain"] == "www.pse.com")
tronikos commented 10 months ago

I added this line in the code. Just pull the latest changes and try again.

fallenpegasus commented 10 months ago

I'll do that. I was looking at the chrome console last night, trying to figure this out, and noticed that the verification token was already in the cookies. Wouldn't it be better (fewer round trips) to look for the request token in the cookies if its not in the html, and use that? But I will try this.

fallenpegasus commented 10 months ago

It worked! It now shows consumption!

The "readResolution": "QUARTER_HOUR" if that makes a difference

And it's not showing the dollar costs. I'll open a other issue for that.

Thank you

chen-ye commented 10 months ago

thanks for fixing this @tronikos. apologies for not hopping onto it