From f0f8073afc868e78a3de91eac97f60b472f4b48c Mon Sep 17 00:00:00 2001 From: hulk Date: Mon, 14 Sep 2026 15:12:16 +0800 Subject: [PATCH] =?UTF-8?q?fix(DLPilot):=20publish=5Fgitea=20=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E8=87=AA=E5=8A=A8=E9=87=8D=E8=AF=95(=E5=AE=9E?= =?UTF-8?q?=E4=BE=8B=20TLS=20=E9=97=B4=E6=AD=87=E6=80=A7=20SSL=20EOF)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HDMI-Tool/src/publish_gitea.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/HDMI-Tool/src/publish_gitea.py b/HDMI-Tool/src/publish_gitea.py index 87f95c7..94ed15c 100644 --- a/HDMI-Tool/src/publish_gitea.py +++ b/HDMI-Tool/src/publish_gitea.py @@ -23,6 +23,7 @@ import re import ssl import subprocess import sys +import time import urllib.error import urllib.request import uuid @@ -59,15 +60,22 @@ class Api: self.headers = {'Authorization': f'token {token}'} self.ctx = ssl._create_unverified_context() if insecure else None - def request(self, method, path, data=None, headers=None): - req = urllib.request.Request(self.api + path, data=data, method=method, - headers={**self.headers, **(headers or {})}) - try: - with urllib.request.urlopen(req, context=self.ctx) as resp: - body = resp.read() - return resp.status, json.loads(body) if body else None - except urllib.error.HTTPError as e: - return e.code, json.loads(e.read() or b'{}') + def request(self, method, path, data=None, headers=None, retries=4): + """发请求; 实例 TLS 间歇性抽风(SSL UNEXPECTED_EOF), 连接级错误自动重试""" + last = None + for attempt in range(retries): + req = urllib.request.Request(self.api + path, data=data, method=method, + headers={**self.headers, **(headers or {})}) + try: + with urllib.request.urlopen(req, context=self.ctx) as resp: + body = resp.read() + return resp.status, json.loads(body) if body else None + except urllib.error.HTTPError as e: + return e.code, json.loads(e.read() or b'{}') + except (urllib.error.URLError, ssl.SSLError, OSError) as e: + last = e + time.sleep(1.0 + attempt) + raise RuntimeError(f'Gitea 请求连续 {retries} 次失败: {last}') def get_json(self, path): status, data = self.request('GET', path)