From edff9ae3222733822bb0de78532038d4e53c960a Mon Sep 17 00:00:00 2001 From: RoboMagus <68224306+RoboMagus@users.noreply.github.com> Date: Tue, 11 Oct 2022 01:01:31 +0200 Subject: [PATCH] Proxy friendly host url resolution for `use_address` with path. (#3653) --- esphome/helpers.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/esphome/helpers.py b/esphome/helpers.py index 85a767036a..b5a6306342 100644 --- a/esphome/helpers.py +++ b/esphome/helpers.py @@ -6,6 +6,7 @@ import os from pathlib import Path from typing import Union import tempfile +from urllib.parse import urlparse _LOGGER = logging.getLogger(__name__) @@ -134,7 +135,8 @@ def resolve_ip_address(host): errs.append(str(err)) 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: errs.append(str(err)) raise EsphomeError(f"Error resolving IP address: {', '.join(errs)}") from err