Proxy friendly host url resolution for use_address with path. (#3653)

This commit is contained in:
RoboMagus 2022-10-11 01:01:31 +02:00 committed by GitHub
parent 3c2766448d
commit edff9ae322
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -6,6 +6,7 @@ import os
from pathlib import Path from pathlib import Path
from typing import Union from typing import Union
import tempfile import tempfile
from urllib.parse import urlparse
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -134,7 +135,8 @@ def resolve_ip_address(host):
errs.append(str(err)) errs.append(str(err))
try: try:
return socket.gethostbyname(host) host_url = host if (urlparse(host).scheme != "") else "http://" + host
return socket.gethostbyname(urlparse(host_url).hostname)
except OSError as err: except OSError as err:
errs.append(str(err)) errs.append(str(err))
raise EsphomeError(f"Error resolving IP address: {', '.join(errs)}") from err raise EsphomeError(f"Error resolving IP address: {', '.join(errs)}") from err