fix: 更新检查改用浏览器 UA
git.fragrance.moe 走 Cloudflare,非浏览器 UA 会被 403 error 1010
This commit is contained in:
1 parent
4223b0cd19
commit
132ff656e1
2 files changed
+14
-1
No files matched your search
@@ -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
|
||||
```
|
||||
|
||||
+7
-1
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user