Fix secrets download on self-hosted runners: use urllib stdlib instead of requests
This commit is contained in:
@@ -20,20 +20,21 @@ jobs:
|
|||||||
retry_wait_seconds: 15
|
retry_wait_seconds: 15
|
||||||
shell: python
|
shell: python
|
||||||
command: |
|
command: |
|
||||||
import requests
|
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
|
import urllib.request
|
||||||
|
|
||||||
input_data = json.loads('${{ inputs.zip_url_json }}')
|
input_data = json.loads('${{ inputs.zip_url_json }}')
|
||||||
url = f"{input_data['url']}/get_zip?filename={input_data['file']}"
|
url = f"{input_data['url']}/get_zip?filename={input_data['file']}"
|
||||||
|
|
||||||
for attempt in range(5):
|
for attempt in range(5):
|
||||||
try:
|
try:
|
||||||
print(f"Downloading (Attempt {attempt + 1})...")
|
print(f"Downloading (Attempt {attempt + 1})...")
|
||||||
r = requests.get(url, timeout=20)
|
# 仅使用标准库(urllib),兼容未预装 requests 的自建 runner 容器
|
||||||
r.raise_for_status()
|
with urllib.request.urlopen(url, timeout=20) as r:
|
||||||
|
content = r.read()
|
||||||
with open('secrets.zip', 'wb') as f:
|
with open('secrets.zip', 'wb') as f:
|
||||||
f.write(r.content)
|
f.write(content)
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if attempt < 4:
|
if attempt < 4:
|
||||||
|
|||||||
@@ -19,20 +19,21 @@ jobs:
|
|||||||
retry_wait_seconds: 15
|
retry_wait_seconds: 15
|
||||||
shell: python
|
shell: python
|
||||||
command: |
|
command: |
|
||||||
import requests
|
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
|
import urllib.request
|
||||||
|
|
||||||
input_data = json.loads('${{ inputs.zip_url_json }}')
|
input_data = json.loads('${{ inputs.zip_url_json }}')
|
||||||
url = f"{input_data['url']}/get_zip?filename={input_data['file']}"
|
url = f"{input_data['url']}/get_zip?filename={input_data['file']}"
|
||||||
|
|
||||||
for attempt in range(5):
|
for attempt in range(5):
|
||||||
try:
|
try:
|
||||||
print(f"Downloading (Attempt {attempt + 1})...")
|
print(f"Downloading (Attempt {attempt + 1})...")
|
||||||
r = requests.get(url, timeout=20)
|
# 仅使用标准库(urllib),无需预装 requests,兼容各类 runner 环境
|
||||||
r.raise_for_status()
|
with urllib.request.urlopen(url, timeout=20) as r:
|
||||||
|
content = r.read()
|
||||||
with open('secrets.zip', 'wb') as f:
|
with open('secrets.zip', 'wb') as f:
|
||||||
f.write(r.content)
|
f.write(content)
|
||||||
break
|
break
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if attempt < 4:
|
if attempt < 4:
|
||||||
|
|||||||
Reference in New Issue
Block a user