From 8b21ef8502d5a2d7e323449622ab0e3b3326cedc Mon Sep 17 00:00:00 2001 From: zhuhjay Date: Mon, 9 Nov 2026 13:02:37 +0800 Subject: [PATCH] =?UTF-8?q?fix(cmcc):=20webhook=20=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E8=AF=8A=E6=96=AD=EF=BC=88400=20=E5=8F=AA=E6=8A=A5=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E7=A0=81=E7=AD=89=E4=BA=8E=E7=9E=8E=E7=9C=BC=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 真机 2026-11-09 08:40 首跑:webhook HTTP 400,日志只有「失败」两个字, 无从判断是鉴权头缺失、Content-Type 与模板矛盾,还是路径不对。 现在失败时打:请求体前 80 字符 + 服务端响应前 300 字符 + 400/401/403 分诊提示。 --- cmcc/scrip_cmcc_mark.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cmcc/scrip_cmcc_mark.py b/cmcc/scrip_cmcc_mark.py index f88459a..24a3c44 100644 --- a/cmcc/scrip_cmcc_mark.py +++ b/cmcc/scrip_cmcc_mark.py @@ -172,7 +172,17 @@ def send_notify(title, content): r = requests.post(hook, data=body.encode("utf-8"), headers=hdrs, timeout=15) ok = 200 <= r.status_code < 300 sent = sent or ok - log("[通知] webhook HTTP %d %s" % (r.status_code, "成功" if ok else "失败")) + if ok: + log("[通知] webhook HTTP %d 成功" % r.status_code) + else: + # ★ 400/401 必须看到服务端说了什么,否则永远不知道为什么推不出去 + log("[通知] webhook HTTP %d 失败 | 请求体前80=%r | 响应=%r" % ( + r.status_code, body[:80], (r.text or "")[:300])) + if r.status_code in (401, 403): + log("[通知] 提示:webhook 需要鉴权头,检查 WEBHOOK_HEADERS 里有没有 Token/Authorization 行") + elif r.status_code == 400: + log("[通知] 提示:服务端嫌请求体不合法。核对 WEBHOOK_CONTENT_TYPE 与 WEBHOOK_BODY 模板是否自相矛盾" + "(JSON 内容必须配 application/json)") except Exception as e: log("[通知] webhook 异常 %r" % e) if token: