From 32918755f34912835d042bb076a2bd1aaffdd5b5 Mon Sep 17 00:00:00 2001 From: naeeo Date: Tue, 29 Sep 2026 23:08:13 +0800 Subject: [PATCH] Fix secrets download on self-hosted runners: use urllib stdlib instead of requests --- .gitea/workflows/fetch-encrypted-secrets.yml | 11 ++++++----- .github/workflows/fetch-encrypted-secrets.yml | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.gitea/workflows/fetch-encrypted-secrets.yml b/.gitea/workflows/fetch-encrypted-secrets.yml index e097d83..bdc8159 100644 --- a/.gitea/workflows/fetch-encrypted-secrets.yml +++ b/.gitea/workflows/fetch-encrypted-secrets.yml @@ -20,20 +20,21 @@ jobs: retry_wait_seconds: 15 shell: python command: | - import requests import json import time + import urllib.request input_data = json.loads('${{ inputs.zip_url_json }}') url = f"{input_data['url']}/get_zip?filename={input_data['file']}" - + for attempt in range(5): try: print(f"Downloading (Attempt {attempt + 1})...") - r = requests.get(url, timeout=20) - r.raise_for_status() + # 仅使用标准库(urllib),兼容未预装 requests 的自建 runner 容器 + with urllib.request.urlopen(url, timeout=20) as r: + content = r.read() with open('secrets.zip', 'wb') as f: - f.write(r.content) + f.write(content) break except Exception as e: if attempt < 4: diff --git a/.github/workflows/fetch-encrypted-secrets.yml b/.github/workflows/fetch-encrypted-secrets.yml index 6ccad6b..7ce80f8 100644 --- a/.github/workflows/fetch-encrypted-secrets.yml +++ b/.github/workflows/fetch-encrypted-secrets.yml @@ -19,20 +19,21 @@ jobs: retry_wait_seconds: 15 shell: python command: | - import requests import json import time + import urllib.request input_data = json.loads('${{ inputs.zip_url_json }}') url = f"{input_data['url']}/get_zip?filename={input_data['file']}" - + for attempt in range(5): try: print(f"Downloading (Attempt {attempt + 1})...") - r = requests.get(url, timeout=20) - r.raise_for_status() + # 仅使用标准库(urllib),无需预装 requests,兼容各类 runner 环境 + with urllib.request.urlopen(url, timeout=20) as r: + content = r.read() with open('secrets.zip', 'wb') as f: - f.write(r.content) + f.write(content) break except Exception as e: if attempt < 4: