From ed2ff52bf4391c22a927807d7b083c4c9020dc19 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 25 Jun 2026 10:16:17 +0800 Subject: [PATCH] =?UTF-8?q?fix(wecom):=20diag=5Fwecom=20=E5=8A=A0=20sys.pa?= =?UTF-8?q?th=20=E4=BB=93=E5=BA=93=E6=A0=B9=20+=20=E6=89=8B=E5=8A=A8=20.en?= =?UTF-8?q?v=20=E5=85=9C=E5=BA=95(=E7=9B=B4=E8=B7=91=E4=B8=8D=E5=86=8D=20M?= =?UTF-8?q?oduleNotFoundError)+=20bump=200.26.5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 诊断已定位线上 60020:应用「企业可信IP」白名单未含服务器出口 IP。 Co-Authored-By: Claude Opus 4.8 (1M context) --- core/__init__.py | 2 +- scripts/diag_wecom.py | 32 +++++++++++++++++++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/core/__init__.py b/core/__init__.py index 1988beb..129738c 100644 --- a/core/__init__.py +++ b/core/__init__.py @@ -1,3 +1,3 @@ # zcbot 版本号单一事实源:web/app.py 的 FastAPI version、/healthz 返回、前端展示都引这里。 # 改版本只动这一行。 -__version__ = "0.26.4" +__version__ = "0.26.5" diff --git a/scripts/diag_wecom.py b/scripts/diag_wecom.py index c161ae6..67570f2 100644 --- a/scripts/diag_wecom.py +++ b/scripts/diag_wecom.py @@ -12,11 +12,33 @@ import os import sys -try: - from dotenv import find_dotenv, load_dotenv - load_dotenv(find_dotenv()) -except Exception: - pass +# 仓库根加入 sys.path(脚本在 scripts/ 下,直跑时 core 在上一级) +_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +if _ROOT not in sys.path: + sys.path.insert(0, _ROOT) + + +def _load_env(path: str) -> None: + """加载 .env:优先 python-dotenv,没装则手动解析(只填未设置的 key)。""" + try: + from dotenv import load_dotenv + load_dotenv(path) + return + except Exception: + pass + try: + with open(path, encoding="utf-8") as f: + for line in f: + line = line.strip() + if not line or line.startswith("#") or "=" not in line: + continue + k, v = line.split("=", 1) + os.environ.setdefault(k.strip(), v.strip().strip('"').strip("'")) + except FileNotFoundError: + pass + + +_load_env(os.path.join(_ROOT, ".env")) from core.wechat import wecom