From 132ff656e1b25462259cc04491b0521e176bf9ea Mon Sep 17 00:00:00 2001 From: shouko Date: Wed, 28 Oct 2026 22:36:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E6=94=B9=E7=94=A8=E6=B5=8F=E8=A7=88=E5=99=A8=20UA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git.fragrance.moe 走 Cloudflare,非浏览器 UA 会被 403 error 1010 --- README.md | 7 +++++++ maipulse/app.py | 8 +++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8488918..e4e953e 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,13 @@ android/ Android 壳工程(Gradle + MainActivity) ## 跑起来 +先把配置模板复制一份,否则 import 会缺 config: + +```bash +cd astral && cp config.py.example config.py +``` + + ```bash python app.py # http://127.0.0.1:8787 ``` diff --git a/maipulse/app.py b/maipulse/app.py index e287911..878d9c6 100644 --- a/maipulse/app.py +++ b/maipulse/app.py @@ -912,6 +912,8 @@ def api_update_gh(): repo=repo) +UA_BROWSER = ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " + "(KHTML, like Gecko) Chrome/120.0 Safari/537.36") UPDATE_SITE = "https://git.fragrance.moe" UPDATE_REPO = "shouko/maipulse" @@ -950,7 +952,11 @@ def api_update_check(): api = "%s/api/v1/repos/%s/releases/latest" % (UPDATE_SITE, UPDATE_REPO) try: - req = urllib.request.Request(api, headers={"User-Agent": "maipulse/" + APP_VERSION}) + # Cloudflare 会拦非浏览器 UA(403 error code 1010),必须伪装成普通浏览器 + req = urllib.request.Request(api, headers={ + "User-Agent": UA_BROWSER, + "Accept": "application/json", + }) rel = json.loads(urllib.request.urlopen(req, timeout=20).read().decode("utf-8")) except urllib.error.HTTPError as exc: return fail("Release 接口 HTTP %s(仓库或 Release 不存在)" % exc.code)