home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
72.73k stars 30.46k forks source link

Opower - Unknown error occurred from SMUD Unresolved 2024.4.1 #114989

Closed luckygenes-dw closed 1 week ago

luckygenes-dw commented 6 months ago

The problem

Selected Add Entry then selected Sacramento Municipal Utility District (SMUD) from dropdown list, entered credentials for SMUD account then clicked submit. Integration appeared to be processing request then after a few seconds, integration displayed "Unknown error occurred".

What version of Home Assistant Core has the issue?

core-2024.4.1

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Opower

Link to integration documentation on our website

https://www.home-assistant.io/integrations/opower

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/opower/config_flow.py", line 84, in async_step_user
    errors = await _validate_login(self.hass, user_input)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/opower/config_flow.py", line 50, in _validate_login
    await api.async_login()
  File "/usr/local/lib/python3.12/site-packages/opower/opower.py", line 193, in async_login
    self.access_token = await self.utility.async_login(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/opower/utilities/smud.py", line 199, in async_login
    okta_login_2_url = SMUD.get_okta_url_from_response_redirect(
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/opower/utilities/smud.py", line 336, in get_okta_url_from_response_redirect
    return query_parts["redirectUrl"][0]

Additional information

No response

home-assistant[bot] commented 6 months ago

Hey there @tronikos, mind taking a look at this issue as it has been labeled with an integration (opower) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `opower` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign opower` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


opower documentation opower source (message by IssueLinks)

tronikos commented 6 months ago

@BrianHenryIE who added support for SMUD login

@luckygenes-dw it would be good to run python src/demo.py -vv 2> out.txt from https://github.com/tronikos/opower and provide the output to @BrianHenryIE for debugging and fixing.

luckygenes-dw commented 6 months ago

@tronikos - Have no Python knowledge to execute your request. Is there a tutorial or guide?

kylemwhite commented 6 months ago

I am having the same issue. Also, I am not a Python person but I was able to download and run the script. Here's the output:

python : Traceback (most recent call last):
At line:1 char:1
+ python .\demo.py -vv 2> out.txt
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Traceback (most recent call last)::String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

  File "....\src\demo.py", line 10, in 
    import aiohttp
ModuleNotFoundError: No module named 'aiohttp'

So I ran pip3 install aiohttp and it complained about No module named 'arrow', so I ran pip3 install arrow and again for pyotp... and then re-ran the script. It just hung without writing any output at all to out.txt... so I let it sit while I took a shower, and when I came back... still nothing :(

So, I started looking at the code and debugging with VS Code and I could see where it got stuck, it's right after the login.

My SMUD profile was at one time used for two accounts, mine and my father's house. His account no longer shows up (not sure why) but the point is that after I log in, I do not immediately see my data, I must first select which account I want to view (even though currently there is only one to choose from). I suspect the script was developed assuming that there is only one account associated with the login and therefore expects to see that data page immediately after logging in, not a page that requires you to select the account. I tested this theory using my father's login (which has only ever been connected to his account) and it worked!

I don't know how to make the page go directly to my account, that might be a phone call with SMUD. It would be nice (although understandably an edge case) if the script could take this into account and maybe provide an argument to specify which account to connect to after logging in. In the meantime, I'll try to get SMUD to completely disassociate my father's account with my login so that I (and the script) don't have to go through that extra step.

Hope that helps.

luckygenes-dw commented 6 months ago

@kylemwhite My SMUD profile is like you. I have two SMUD accounts tied to my profile. I called SMUD to get the second account de-linked from my profile and was told by SMUD rep, my second account doesn't active service and would not be able to de-link but the system will de-link the second account after 6-months of no active service. Crossing my fingers the second account de-links after 6-months since it's just around the corner.

I tested your theory using a family members SMUD login and the Opower integration was successful.

tronikos commented 6 months ago

@kylemwhite since you managed to debug the code with VS Code on your own you are half way there to resolve this on your own too. In your web browser open developer tools > network and login to the SMUD website. There you can see the requests made. Now it's a matter of changing the Python code to match those requests.

BrianHenryIE commented 5 months ago

@luckygenes-dw @kylemwhite I'm happy to meet at a coffee shop and hash this out. I live in midtown. It's too difficult to solve without a login that's experiencing the issue, and I'll be far more motivated to set aside the time to work on it if I've to show up somewhere to meet someone.

luckygenes-dw commented 4 months ago

@BrianHenryIE. Thanks for reaching out and your offer to assist. I no longer have multiple accounts tied to my SMUD profile.

skarchmit commented 4 months ago

I just created a smud account. Single account, no other accounts, I’m having an authentication issue in this integration, while authenticating on the website directly is just fine.

Unrelated, but my PG&E account is just fine. It’s just this one.

BrianHenryIE commented 4 months ago

@skarchmit Could you try these steps and let me know what you see? https://github.com/andylittle/opower-smud/pull/1#issuecomment-1904683976 (except where it says "checkout the PR" because it has already been merged)

edit: I see your comment at https://github.com/tronikos/opower/issues/82#issuecomment-2150672192 – I've subscribed to that in case you open it again.

jev-on commented 3 months ago

@BrianHenryIE maybe you can help me with a similar error ("Unknown error occurred ") I'm seeing when trying to log into SMUD through opower. I'm using HA 2024.7.0.

I followed the instructions here https://github.com/andylittle/opower-smud/pull/1#issuecomment-1904683976 and I'm getting the output below.

Traceback (most recent call last):
  File "/Users/.../Downloads/opower-smud/.venv/lib/python3.12/site-packages/aiohttp/connector.py", line 1025, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 1147, in create_connection
    transport, protocol = await self._create_connection_transport(
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 1180, in _create_connection_transport
    await waiter
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/sslproto.py", line 578, in _on_handshake_complete
    raise handshake_exc
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/sslproto.py", line 560, in _do_handshake
    self._sslobj.do_handshake()
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/ssl.py", line 917, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/.../Downloads/opower-smud/src/demo.py", line 170, in <module>
    asyncio.run(_main())
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 685, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/.../Downloads/opower-smud/src/demo.py", line 86, in _main
    await opower.async_login()
  File "/Users/.../Downloads/opower-smud/src/opower/opower.py", line 194, in async_login
    self.access_token = await self.utility.async_login(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/.../Downloads/opower-smud/src/opower/utilities/smud.py", line 108, in async_login
    myaccount_response = await session.get(
                         ^^^^^^^^^^^^^^^^^^
  File "/Users/.../Downloads/opower-smud/.venv/lib/python3.12/site-packages/aiohttp/client.py", line 581, in _request
    conn = await self._connector.connect(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/.../Downloads/opower-smud/.venv/lib/python3.12/site-packages/aiohttp/connector.py", line 544, in connect
    proto = await self._create_connection(req, traces, timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/.../Downloads/opower-smud/.venv/lib/python3.12/site-packages/aiohttp/connector.py", line 944, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/.../Downloads/opower-smud/.venv/lib/python3.12/site-packages/aiohttp/connector.py", line 1257, in _create_direct_connection
    raise last_exc
  File "/Users/.../Downloads/opower-smud/.venv/lib/python3.12/site-packages/aiohttp/connector.py", line 1226, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/.../Downloads/opower-smud/.venv/lib/python3.12/site-packages/aiohttp/connector.py", line 1027, in _wrap_create_connection
    raise ClientConnectorCertificateError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host myaccount.smud.org:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)')]

Thanks.

issue-triage-workflows[bot] commented 2 weeks ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.