Skip to content

Commit eb7c346

Browse files
authored
Bugfix/fix latest pypi version check (apache#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
1 parent 84769be commit eb7c346

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

dev/breeze/src/airflow_breeze/utils/version_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ def get_latest_helm_chart_version():
3131
def get_latest_airflow_version():
3232
import requests
3333

34-
response = requests.get("https://pypi.org/pypi/apache-airflow/json")
34+
response = requests.get(
35+
"https://pypi.org/pypi/apache-airflow/json", headers={"User-Agent": "Python requests"}
36+
)
3537
response.raise_for_status()
3638
latest_released_version = response.json()["info"]["version"]
3739
return latest_released_version

dev/validate_version_added_fields_in_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747

4848
def fetch_pypi_versions() -> list[str]:
49-
r = requests.get("https://pypi.org/pypi/apache-airflow/json")
49+
r = requests.get("https://pypi.org/pypi/apache-airflow/json", headers={"User-Agent": "Python requests"})
5050
r.raise_for_status()
5151
all_version = r.json()["releases"].keys()
5252
released_versions = [d for d in all_version if not (("rc" in d) or ("b" in d))]

docker-tests/tests/docker_tests/test_examples_of_prod_image_building.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@
4242

4343
@cache
4444
def get_latest_airflow_image():
45-
response = requests.get("https://pypi.org/pypi/apache-airflow/json")
45+
response = requests.get(
46+
"https://pypi.org/pypi/apache-airflow/json", headers={"User-Agent": "Python requests"}
47+
)
4648
response.raise_for_status()
4749
latest_released_version = response.json()["info"]["version"]
4850
return f"apache/airflow:{latest_released_version}"

scripts/ci/airflow_version_check.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ def check_airflow_version(airflow_version: Version) -> tuple[str, bool]:
4545
returns: tuple containing the version and a boolean indicating if it's latest.
4646
"""
4747
latest = False
48-
url = "https://pypi.org/pypi/apache-airflow/json"
4948
try:
50-
response = requests.get(url)
49+
response = requests.get(
50+
"https://pypi.org/pypi/apache-airflow/json", headers={"User-Agent": "Python requests"}
51+
)
5152
response.raise_for_status()
5253
data = response.json()
5354
latest_version = Version(data["info"]["version"])

scripts/ci/pre_commit/update_installers_and_pre_commit.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@
5555

5656

5757
def get_latest_pypi_version(package_name: str) -> str:
58-
response = requests.get(f"https://pypi.org/pypi/{package_name}/json")
58+
response = requests.get(
59+
f"https://pypi.org/pypi/{package_name}/json", headers={"User-Agent": "Python requests"}
60+
)
5961
response.raise_for_status() # Ensure we got a successful response
6062
data = response.json()
6163
latest_version = data["info"]["version"] # The version info is under the 'info' key

0 commit comments

Comments
 (0)