Skip to content

Commit 0a85e29

Browse files
authored
Work around CDN rate limiting on Python.org in bin/update_pythons.py (#2753)
1 parent 2d33864 commit 0a85e29

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

bin/update_pythons.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,11 @@ def __init__(self) -> None:
266266

267267
# Removing the prefix
268268
version = Version(release["name"].removeprefix("Python "))
269+
self.versions_dict[version] = release["resource_uri"]
269270

270-
uri = int(release["resource_uri"].rstrip("/").split("/")[-1])
271-
self.versions_dict[version] = uri
271+
files_response = requests.get("https://www.python.org/api/v2/downloads/release_file/")
272+
files_response.raise_for_status()
273+
self.files_info = files_response.json()
272274

273275
def update_version(self, identifier: str, spec: Specifier, file_ident: str) -> ConfigUrl | None:
274276
# see note above on Specifier.filter
@@ -278,13 +280,9 @@ def update_version(self, identifier: str, spec: Specifier, file_ident: str) -> C
278280
for new_version in sorted_versions:
279281
# Find the first patch version that contains the requested file
280282
uri = self.versions_dict[new_version]
281-
response = requests.get(
282-
f"https://www.python.org/api/v2/downloads/release_file/?release={uri}"
283-
)
284-
response.raise_for_status()
285-
file_info = response.json()
283+
files = [rf for rf in self.files_info if rf["release"] == uri]
286284

287-
urls = [rf["url"] for rf in file_info if file_ident in rf["url"]]
285+
urls = [rf["url"] for rf in files if file_ident in rf["url"]]
288286
if urls:
289287
return ConfigUrl(
290288
identifier=identifier,

0 commit comments

Comments
 (0)