diff --git a/airflow/providers/elasticsearch/log/es_task_handler.py b/airflow/providers/elasticsearch/log/es_task_handler.py index 0a85f178badac..97d46be8b6208 100644 --- a/airflow/providers/elasticsearch/log/es_task_handler.py +++ b/airflow/providers/elasticsearch/log/es_task_handler.py @@ -143,7 +143,9 @@ def format_url(host: str) -> str: parsed_url = urlparse(host) # Check if the scheme is either http or https - if not parsed_url.scheme: + # Handles also the Python 3.9+ case where urlparse understands "localhost:9200" + # differently than urlparse in Python 3.8 and below (https://github.com/psf/requests/issues/6455) + if parsed_url.scheme not in ("http", "https"): host = "http://" + host parsed_url = urlparse(host)