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
73.7k stars 30.83k forks source link

PSOklahoma Opower Virtual "Name does not resolve" #106989

Closed chrishas35 closed 10 months ago

chrishas35 commented 10 months ago

The problem

When configuring Opower for Public Service Company of Oklahoma (PSO), a "Name does not resolve" error is returned.

What version of Home Assistant Core has the issue?

core-2024.1.0

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

psoklahoma

Link to integration documentation on our website

https://home-assistant.io/integrations/psoklahoma

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Logger: aiohttp.server
Source: /usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py:421
First occurred: 2:35:13 PM (1 occurrences)
Last logged: 2:35:13 PM

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 1173, in _create_direct_connection
    hosts = await asyncio.shield(host_resolved)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 884, in _resolve_host
    addrs = await self._resolver.resolve(host, port, family=self._family)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/resolver.py", line 33, in resolve
    infos = await self._loop.getaddrinfo(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 867, in getaddrinfo
    return await self.run_in_executor(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/socket.py", line 962, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
socket.gaierror: [Errno -2] Name does not resolve

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

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 452, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_app.py", line 543, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 114, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 233, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 31, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 149, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 63, in with_admin
    return await func(self, request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 177, in post
    return await super().post(request, flow_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 72, in wrapper
    result = await method(view, request, data, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 110, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 323, in async_configure
    result = await self._async_handle_step(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 419, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/opower/config_flow.py", line 83, in async_step_user
    errors = await _validate_login(self.hass, user_input)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/opower/config_flow.py", line 49, in _validate_login
    await api.async_login()
  File "/usr/local/lib/python3.11/site-packages/opower/opower.py", line 193, in async_login
    self.access_token = await self.utility.async_login(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/opower/utilities/aepbase.py", line 158, in async_login
    await async_auth_saml(session, url)
  File "/usr/local/lib/python3.11/site-packages/opower/utilities/helpers.py", line 27, in async_auth_saml
    async with session.get(url) as resp:
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 1187, in __aenter__
    self._resp = await self._coro
                 ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 574, in _request
    conn = await self._connector.connect(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 544, in connect
    proto = await self._create_connection(req, traces, timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 911, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 1187, in _create_direct_connection
    raise ClientConnectorError(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host fim.psoklahoma.com:443 ssl:default [Name does not resolve]

Additional information

No response

home-assistant[bot] commented 10 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)

UPEngineer commented 10 months ago

I was just coming to report the same issue. Exact same issue and errors that @chrishas35 received trying to implement Public Service Company of Oklahoma (psoklahoma).

chrishas35 commented 10 months ago

Unclear if it matters as it doesn't appear to be reaching Opower yet(?), but when inspecting network activity when logged into PSOklahoma.com, I'm seeing traffic going to pso.opower.com.

samanthavbarron commented 10 months ago

FWIW I'm getting something similar for ConEd

Logger: aiohttp.server
Source: /usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py:421 
First occurred: 10:34:19 PM (2 occurrences) 
Last logged: 10:37:03 PM

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 992, in _wrap_create_connection
    return await self._loop.create_connection(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 1085, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 1069, in create_connection
    sock = await self._connect_sock(
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 973, in _connect_sock
    await self.sock_connect(sock, address)
  File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 628, in sock_connect
    return await fut
           ^^^^^^^^^
  File "/usr/local/lib/python3.11/asyncio/selector_events.py", line 668, in _sock_connect_cb
    raise OSError(err, f'Connect call failed {address}')
TimeoutError: [Errno 110] Connect call failed ('158.57.194.119', 443)

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

Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 452, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_app.py", line 543, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 114, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 233, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 31, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 149, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 63, in with_admin
    return await func(self, request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 177, in post
    return await super().post(request, flow_id)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 72, in wrapper
    result = await method(view, request, data, *args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 110, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 293, in async_configure
    result = await self._async_handle_step(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 389, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/opower/config_flow.py", line 99, in async_step_mfa
    errors = await _validate_login(self.hass, data)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/opower/config_flow.py", line 49, in _validate_login
    await api.async_login()
  File "/usr/local/lib/python3.11/site-packages/opower/opower.py", line 193, in async_login
    self.access_token = await self.utility.async_login(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/opower/utilities/coned.py", line 70, in async_login
    async with session.post(
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 1187, in __aenter__
    self._resp = await self._coro
                 ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 574, in _request
    conn = await self._connector.connect(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 544, in connect
    proto = await self._create_connection(req, traces, timeout)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 911, in _create_connection
    _, proto = await self._create_direct_connection(req, traces, timeout)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 1235, in _create_direct_connection
    raise last_exc
  File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 1204, in _create_direct_connection
    transp, proto = await self._wrap_create_connection(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 1000, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host www.coned.com:443 ssl:default [Connect call failed ('158.57.194.119', 443)]
tronikos commented 10 months ago

At discord another user reported a similar issue: aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host fim.aepohio.com:443 ssl:default [Name does not resolve]

@joewashear007 added support for AEP Ohio and I generalized it for all AEP utilities after a user gave me their account credentials. @joewashear007 does it still work for you?

I don't have access to an AEP account. My suggestion is to try running demo.py in https://github.com/tronikos/opower from your typical laptop/desktop and running it again from your Home Assistant environment. Hopefully that could help you debug what's going on.

tmcb82 commented 10 months ago

At discord another user reported a similar issue: aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host fim.aepohio.com:443 ssl:default [Name does not resolve]

@joewashear007 added support for AEP Ohio and I generalized it for all AEP utilities after a user gave me their account credentials. @joewashear007 does it still work for you?

I don't have access to an AEP account. My suggestion is to try running demo.py in https://github.com/tronikos/opower from your typical laptop/desktop and running it again from your Home Assistant environment. Hopefully that could help you debug what's going on.

I have AEP Ohio and when I try to log it it just says “Unknown error occurred.”

UPEngineer commented 10 months ago

Well, I am going to have to wait for someone smarter to figure this out as I have zero experience with Python. Maybe @tronikos would be willing to use my credentials to get into PSOklahoma? If so, let me know what I need to do to get it to you.

Scott

talex-05 commented 10 months ago

response from demo.py when trying to access AEP ohio:

Exception has occurred: ClientConnectorCertificateError Cannot connect to host www.aepohio.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)')] 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:

File "/Downloads/opower-main/src/opower/utilities/aepbase.py", line 119, in async_login async with session.get( File "/Downloads/opower-main/src/opower/opower.py", line 193, in async_login self.access_token = await self.utility.async_login( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Downloads/opower-main/src/demo.py", line 86, in _main await opower.async_login() File "/Downloads/opower-main/src/demo.py", line 170, in asyncio.run(_main()) aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host www.aepohio.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)')]

apaperclip commented 10 months ago

I have the [Name does not resolve] issue too.

I'm running latest HA release on docker and spent some time looking at DNS. Randomly I was able to get the integration to work once but then it started failing again. Using demo.py I found that it will work every once and a while. Demo.py via aiohttp does an A and AAAA query for the dns name.

My HA container uses a local dns resolver on pfsense (unbound) and 1.1.1.1. I found that when demo.py would work, it was getting a NO ERORR response from my local resolver for the fim. name quad A query before a NXDOMAIN is returned from 1.1.1.1. When demo.py fails, the AAAA queries get an NXDOMAIN from both DNS servers These quad A NXDOMAIN responses are before the A responses with the IP. So perhaps the aiohttp library or however it handles DNS resolution fails on the NXDOMAIN regardless of a successful NO ERROR response from a different query type later on.

Why my local resolver on pfsesnse sometimes gives a no error response I have no idea, I'll check into that , but I think the issue here is the AAAA query and the NXDOMAIN response and how the client resolver handles that response - or - these providers have their AAAA dns responses misconfigured. I've not gone that route yet.

talex-05 commented 10 months ago

response from demo.py when trying to access AEP ohio:

Exception has occurred: ClientConnectorCertificateError Cannot connect to host www.aepohio.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)')] 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:

File "/Downloads/opower-main/src/opower/utilities/aepbase.py", line 119, in async_login async with session.get( File "/Downloads/opower-main/src/opower/opower.py", line 193, in async_login self.access_token = await self.utility.async_login( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Downloads/opower-main/src/demo.py", line 86, in _main await opower.async_login() File "/Downloads/opower-main/src/demo.py", line 170, in asyncio.run(_main()) aiohttp.client_exceptions.ClientConnectorCertificateError: Cannot connect to host www.aepohio.com:443 ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1000)')]

After running "/Python 3.12/Install Certificates.command" demo.py runs successfully.

Current bill forecast: Forecast(account=Account(customer=Customer(uuid='REDACTED'), uuid='REDACTED', utility_account_id='REDACTED', meter_type=<MeterType.ELEC: 'ELEC'>, read_resolution=None), start_date=datetime.date(2023, 12, 15), end_date=datetime.date(2024, 1, 13), current_date=datetime.date(2024, 1, 4), unit_of_measure=<UnitOfMeasure.KWH: 'KWH'>, usage_to_date=388.0, cost_to_date=0.0, forecasted_usage=602.0, forecasted_cost=0.0, typical_usage=756.0, typical_cost=0.0)

Getting historical data: account= Account(customer=Customer(uuid='REDACTED'), uuid='REDACTED', utility_account_id='REDACTED', meter_type=<MeterType.ELEC: 'ELEC'>, read_resolution=<ReadResolution.QUARTER_HOUR: 'QUARTER_HOUR'>) aggregate_type= day start_date= 2023-12-28 10:54:05.884751 end_date= 2024-01-04 10:54:05.884790 start_time end_time consumption provided_cost start_minus_prev_end end_minus_prev_end 2023-12-28 00:00:00-05:00 2023-12-29 00:00:00-05:00 17.232 0 None None 2023-12-29 00:00:00-05:00 2023-12-30 00:00:00-05:00 17.474 0 0:00:00 1 day, 0:00:00 2023-12-30 00:00:00-05:00 2023-12-31 00:00:00-05:00 21.482 0 0:00:00 1 day, 0:00:00 2023-12-31 00:00:00-05:00 2024-01-01 00:00:00-05:00 26.062 0 0:00:00 1 day, 0:00:00 2024-01-01 00:00:00-05:00 2024-01-02 00:00:00-05:00 21.534 0 0:00:00 1 day, 0:00:00 2024-01-02 00:00:00-05:00 2024-01-03 00:00:00-05:00 22.958 0 0:00:00 1 day, 0:00:00

joewashear007 commented 10 months ago

Hi All

So I see issue like this in my local home assistant install. I am not sure why we are getting cannot connect to host errors. When I run the opower script on it own, it works fine. But when running Home Assistant it has these errors. I just moved last week so I am still unpacking, but I will be trying to figure out what is going on.

Sometimes when trying to add the integration it says “Unknown error occurred.” (like @tmcb82 mention). Waiting a few seconds and trying sometimes works - but it is not ideal. I am curious if adding a retry to the HTTP requests would improve things thought it hard to test when it unreliable fails.

talex-05 commented 10 months ago

As i can get demo.py to run successfully (after running the "install Certificates.command"), I believe it has something to do with Python Certificates in HA

Referencing my previous comments...when trying to add the aepohio integration (unknown error occured) this is the log output.

Logger: aiohttp.server Source: /usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py:421 First occurred: January 3, 2024 at 3:39:42 PM (9 occurrences) Last logged: 11:04:07 AM

Error handling request Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 1173, in _create_direct_connection hosts = await asyncio.shield(host_resolved) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 884, in _resolve_host addrs = await self._resolver.resolve(host, port, family=self._family) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/resolver.py", line 33, in resolve infos = await self._loop.getaddrinfo( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/asyncio/base_events.py", line 867, in getaddrinfo return await self.run_in_executor( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/concurrent/futures/thread.py", line 58, in run result = self.fn(*self.args, **self.kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/socket.py", line 962, in getaddrinfo for res in _socket.getaddrinfo(host, port, family, type, proto, flags): ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ socket.gaierror: [Errno -2] Name does not resolve

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

Traceback (most recent call last): File "/usr/local/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 452, in _handle_request resp = await request_handler(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/web_app.py", line 543, in _handle resp = await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/web_middlewares.py", line 114, in impl return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 233, in auth_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 31, in headers_middleware response = await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 149, in handle result = await handler(request, request.match_info) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 63, in with_admin return await func(self, request, *args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 177, in post return await super().post(request, flow_id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 72, in wrapper result = await method(view, request, data, args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 110, in post result = await self._flow_mgr.async_configure(flow_id, data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 323, in async_configure result = await self._async_handle_step( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 419, in _async_handle_step result: FlowResult = await getattr(flow, method)(user_input) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/opower/config_flow.py", line 83, in async_step_user errors = await _validate_login(self.hass, user_input) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/opower/config_flow.py", line 49, in _validate_login await api.async_login() File "/usr/local/lib/python3.11/site-packages/opower/opower.py", line 193, in async_login self.access_token = await self.utility.async_login( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/opower/utilities/aepbase.py", line 158, in async_login await async_auth_saml(session, url) File "/usr/local/lib/python3.11/site-packages/opower/utilities/helpers.py", line 27, in async_auth_saml async with session.get(url) as resp: File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 1187, in aenter self._resp = await self._coro ^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/client.py", line 574, in _request conn = await self._connector.connect( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 544, in connect proto = await self._create_connection(req, traces, timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 911, in _createconnection , proto = await self._create_direct_connection(req, traces, timeout) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/site-packages/aiohttp/connector.py", line 1187, in _create_direct_connection raise ClientConnectorError(req.connection_key, exc) from exc aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host fim.aepohio.com:443 ssl:default [Name does not resolve]

joewashear007 commented 10 months ago

Looking at the stack traces, i am not sure where it getting the fim.aepohio.com domain from. When I run the opower client locally, I don't think that it has that domain anywhere. I am curious if that is part of the issue since it look like the cert on that url is not valid

image

apaperclip commented 10 months ago

based on some names above I did a focused test with the getaddrinfo method. v6 fails, v4 works.

>>> print(socket.getaddrinfo('fim.psoklahoma.com', None, socket.AF_INET6)[0][4][0])       
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.11/socket.py", line 962, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
socket.gaierror: [Errno -2] Name does not resolve

>>> print(socket.getaddrinfo('fim.psoklahoma.com', None, socket.AF_INET)[0][4][0]) 
167.239.226.165
>>> 

it looks like aiohttp connector.py defaults to 0 (AF_UNSPEC i think) for the family which will do both A and AAAA (I'm learning as I go here so I could be going to a dead end). It may be random but so far I see the A asked first but the AAAA response is faster and returns first in my environment.

apaperclip commented 10 months ago

based on some names above I did a focused test with the getaddrinfo method. v6 fails, v4 works.

>>> print(socket.getaddrinfo('fim.psoklahoma.com', None, socket.AF_INET6)[0][4][0])       
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.11/socket.py", line 962, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
socket.gaierror: [Errno -2] Name does not resolve

>>> print(socket.getaddrinfo('fim.psoklahoma.com', None, socket.AF_INET)[0][4][0]) 
167.239.226.165
>>> 

it looks like aiohttp connector.py defaults to 0 (AF_UNSPEC i think) for the family which will do both A and AAAA (I'm learning as I go here so I could be going to a dead end). It may be random but so far I see the A asked first but the AAAA response is faster and returns first in my environment.

I think I've reached the end of my research. This feels like an aep dns issue. They should not return an NXDOMAIN for AAAAs that have no entry. It could be coded around I suppose by only doing A record queries. but I can't say I'm a fan of that. My work around (which I also don't like) was to create a host override in my pfsense dns resolver to answer the query with the IP. This results in the A working and AAAA getting a NO ERROR (proper behavior). This will get me up and running for now. demo.py is reliable now so we'll see how the integration behaves, I expect it to be solid as well.

tmcb82 commented 10 months ago

AEP Ohio seems to be working to me now, so I don’t know if it was an issue on their end.

joewashear007 commented 10 months ago

I am curious about trying to edit this line: https://github.com/home-assistant/core/blob/afb5f3c031d2d2aa67ba1167bff804ed9bf7c015/homeassistant/components/opower/coordinator.py#L54-L55 to include a family to force the opower component to use ip4.

aiohttp_client.async_get_clientsession(hass, family=2), # socket.AF_INET == 2
tronikos commented 10 months ago

If IPv4 works but IPv6 doesn't we could do a workaround similar to what forecast solar does, see:

https://github.com/home-assistant-libs/forecast_solar/blob/64e570d8141b16683fdc35071d5e785097579a93/forecast_solar/__init__.py#L73-L78

and:

https://github.com/home-assistant-libs/forecast_solar/blob/64e570d8141b16683fdc35071d5e785097579a93/forecast_solar/__init__.py#L106

I'm running HAOS. Using Advanced SSH & Web Terminal I run:

curl -I fim.psoklahoma.com

I got 302. But running the command inside the Home Assistant docker after I run:

docker exec -it $(docker ps -f name=homeassistant -q) bash

I got curl: (6) Could not resolve host: fim.psoklahoma.com

tronikos commented 10 months ago

I opened https://github.com/home-assistant/supervisor/issues/4798

tronikos commented 10 months ago

@joewashear007 that would be a much easier workaround. Can you try modifying the file locally and report back whether it fixes the issue?

apaperclip commented 10 months ago

@joewashear007 that would be a much easier workaround. Can you try modifying the file locally and report back whether it fixes the issue?

seems to work here in HA. It doesn't look like demo.py was affected, it is still failing. Is that expected?

joewashear007 commented 10 months ago

I have just made this change on my instance. It seems to have loaded the data without an issue. I will check again tomorrow to see if it continuous to work.

chrishas35 commented 10 months ago

The DNS for this domain seems rather broken, which may explain the inconsistent results?

https://dnschecker.org/#A/fim.psoklahoma.com

Currently I'm getting about half resolved and half not.

tronikos commented 10 months ago

https://dnschecker.org/#AAAA/fim.psoklahoma.com shows that IPv6 is broken for all servers

apaperclip commented 10 months ago

https://dnschecker.org/#AAAA/fim.psoklahoma.com shows that IPv6 is broken for all servers

I interpreted that as no AAAA response with IPv6 info regardless of correct or incorrect (NO ERROR vs NXDOMAIN). Even a site with a correctly configured AAAA response that has no v6 addresses gives an X. e.g. www.bestbuy.com.

tronikos commented 10 months ago

I see the August integration had similar issues with IPv6. I'm fixing it similarly in https://github.com/home-assistant/core/pull/107203 Thanks @joewashear007 for your suggestion.

chrishas35 commented 10 months ago

Thanks for the fix! This is now working for me in 2024.1.1.