修发布脚本崩在 Gitee 那一步:返回 null 时没有兜住

发 1.9.0 时代码已经推到两个平台了,但建发行版那一步直接崩:

    AttributeError: 'NoneType' object has no attribute 'get'

根因:Gitee 的 GET /releases/tags/{tag} 在「标签存在、但还没有
发行版」时返回的是 **HTTP 200 + JSON 字面量 null**(不是 404)。
于是 json.loads() 得到 None,再取 ["id"] 就炸了。

实测那条接口对 v1.9.0 就是 200 + null 这个响应。

改成容忍 None —— 取不到 id 就走「新建发行版」那条路。

(另外记一笔:这次提交我本来想用 git commit -m 加多行中文,
PowerShell 把引号搞乱了,git 报 Invalid path '/null'。
多行中文提交信息一律用 git commit -F 文件,别用 -m。)
This commit is contained in:
xmz7891
2026-10-07 22:56:51 +08:00
parent 23be281a1b
commit b1d18f2666
2 changed files with 26 additions and 2 deletions
+17
View File
@@ -0,0 +1,17 @@
修发布脚本崩在 Gitee 那一步:返回 null 时没有兜住
发 1.9.0 时代码已经推到两个平台了,但建发行版那一步直接崩:
AttributeError: 'NoneType' object has no attribute 'get'
根因:Gitee 的 GET /releases/tags/{tag} 在「标签存在、但还没有
发行版」时返回的是 **HTTP 200 + JSON 字面量 null**(不是 404)。
于是 json.loads() 得到 None,再取 ["id"] 就炸了。
实测那条接口对 v1.9.0 就是 200 + null 这个响应。
改成容忍 None —— 取不到 id 就走「新建发行版」那条路。
(另外记一笔:这次提交我本来想用 git commit -m 加多行中文,
PowerShell 把引号搞乱了,git 报 Invalid path '/null'。
多行中文提交信息一律用 git commit -F 文件,别用 -m。)
+8 -1
View File
@@ -108,7 +108,14 @@ def gitee_release(token: str, version: str, body: str,
with urllib.request.urlopen(
"%s/releases/tags/%s?access_token=%s" % (api, tag, token),
timeout=60) as resp:
rid = json.loads(resp.read().decode("utf-8", "replace")).get("id")
# ⚠ Gitee 在"标签存在、但还没有发行版"时返回的是 JSON 字面量
# **null**(不是 404)—— 于是 json.loads() 得到 None,
# 再 .get("id") 就是 AttributeError,整个发布脚本崩在半路
# (代码已经推上去了,发行版却建不出来)。
# 实测发 1.9.0 时踩到。所以这里必须容忍 None。
data = json.loads(resp.read().decode("utf-8", "replace"))
rid = (data or {}).get("id")
if rid:
print(" • 该标签已有发行版 id=%s,复用" % rid)
except urllib.error.HTTPError:
pass