This is an automated email from the ASF dual-hosted git repository.

jscheffl pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new eb7c346dd0d Bugfix/fix latest pypi version check (#51039)
eb7c346dd0d is described below

commit eb7c346dd0dcd510fd99f2382aec81d41dc4d0c3
Author: Jens Scheffler <[email protected]>
AuthorDate: Sun May 25 11:34:40 2025 +0200

    Bugfix/fix latest pypi version check (#51039)
    
    * Fix version check from Pypi, requires user agent else raises HTTP 406
    
    * Fix version check from Pypi, requires user agent else raises HTTP 406, 
also other cases in codebase
---
 dev/breeze/src/airflow_breeze/utils/version_utils.py                 | 4 +++-
 dev/validate_version_added_fields_in_config.py                       | 2 +-
 .../tests/docker_tests/test_examples_of_prod_image_building.py       | 4 +++-
 scripts/ci/airflow_version_check.py                                  | 5 +++--
 scripts/ci/pre_commit/update_installers_and_pre_commit.py            | 4 +++-
 5 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/dev/breeze/src/airflow_breeze/utils/version_utils.py 
b/dev/breeze/src/airflow_breeze/utils/version_utils.py
index 43650a10887..eabee9a4b44 100644
--- a/dev/breeze/src/airflow_breeze/utils/version_utils.py
+++ b/dev/breeze/src/airflow_breeze/utils/version_utils.py
@@ -31,7 +31,9 @@ def get_latest_helm_chart_version():
 def get_latest_airflow_version():
     import requests
 
-    response = requests.get("https://pypi.org/pypi/apache-airflow/json";)
+    response = requests.get(
+        "https://pypi.org/pypi/apache-airflow/json";, headers={"User-Agent": 
"Python requests"}
+    )
     response.raise_for_status()
     latest_released_version = response.json()["info"]["version"]
     return latest_released_version
diff --git a/dev/validate_version_added_fields_in_config.py 
b/dev/validate_version_added_fields_in_config.py
index 7ee0fb16b2d..e4814d7a346 100755
--- a/dev/validate_version_added_fields_in_config.py
+++ b/dev/validate_version_added_fields_in_config.py
@@ -46,7 +46,7 @@ CONFIG_TEMPLATE_FORMAT_UPDATE = "2.6.0"
 
 
 def fetch_pypi_versions() -> list[str]:
-    r = requests.get("https://pypi.org/pypi/apache-airflow/json";)
+    r = requests.get("https://pypi.org/pypi/apache-airflow/json";, 
headers={"User-Agent": "Python requests"})
     r.raise_for_status()
     all_version = r.json()["releases"].keys()
     released_versions = [d for d in all_version if not (("rc" in d) or ("b" in 
d))]
diff --git 
a/docker-tests/tests/docker_tests/test_examples_of_prod_image_building.py 
b/docker-tests/tests/docker_tests/test_examples_of_prod_image_building.py
index c92c52e2657..888123db4ee 100644
--- a/docker-tests/tests/docker_tests/test_examples_of_prod_image_building.py
+++ b/docker-tests/tests/docker_tests/test_examples_of_prod_image_building.py
@@ -42,7 +42,9 @@ QUARANTINED_DOCKER_EXAMPLES: dict[str, str] = {
 
 @cache
 def get_latest_airflow_image():
-    response = requests.get("https://pypi.org/pypi/apache-airflow/json";)
+    response = requests.get(
+        "https://pypi.org/pypi/apache-airflow/json";, headers={"User-Agent": 
"Python requests"}
+    )
     response.raise_for_status()
     latest_released_version = response.json()["info"]["version"]
     return f"apache/airflow:{latest_released_version}"
diff --git a/scripts/ci/airflow_version_check.py 
b/scripts/ci/airflow_version_check.py
index 3b6cf453651..45354d29884 100755
--- a/scripts/ci/airflow_version_check.py
+++ b/scripts/ci/airflow_version_check.py
@@ -45,9 +45,10 @@ def check_airflow_version(airflow_version: Version) -> 
tuple[str, bool]:
     returns: tuple containing the version and a boolean indicating if it's 
latest.
     """
     latest = False
-    url = "https://pypi.org/pypi/apache-airflow/json";
     try:
-        response = requests.get(url)
+        response = requests.get(
+            "https://pypi.org/pypi/apache-airflow/json";, 
headers={"User-Agent": "Python requests"}
+        )
         response.raise_for_status()
         data = response.json()
         latest_version = Version(data["info"]["version"])
diff --git a/scripts/ci/pre_commit/update_installers_and_pre_commit.py 
b/scripts/ci/pre_commit/update_installers_and_pre_commit.py
index 1f4b07f77e5..ccc75e13ebc 100755
--- a/scripts/ci/pre_commit/update_installers_and_pre_commit.py
+++ b/scripts/ci/pre_commit/update_installers_and_pre_commit.py
@@ -55,7 +55,9 @@ FILES_TO_UPDATE: list[tuple[Path, bool]] = [
 
 
 def get_latest_pypi_version(package_name: str) -> str:
-    response = requests.get(f"https://pypi.org/pypi/{package_name}/json";)
+    response = requests.get(
+        f"https://pypi.org/pypi/{package_name}/json";, headers={"User-Agent": 
"Python requests"}
+    )
     response.raise_for_status()  # Ensure we got a successful response
     data = response.json()
     latest_version = data["info"]["version"]  # The version info is under the 
'info' key

Reply via email to