美团调用支持 MT_CPS_PROXY 代理配置(修本机开发直连 SSL EOF)

本机/内网开发直连美团(media.meituan.com)会 SSL EOF,必须走本地代理;线上国内服务器直连正常。
- config.py 加 MT_CPS_PROXY(默认空)
- integrations/meituan.py 的 _call 改用 httpx.Client(proxy=MT_CPS_PROXY, trust_env=False):
  显式走配置的代理、不读进程环境 HTTP_PROXY(避免被失效代理误导)
- .env.example 注明:开发填 http://127.0.0.1:7897,线上留空=直连

效果:本地起后端不用再每次手动 set HTTP_PROXY,uvicorn 直接起即可。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
chenshuobo
2026-06-07 23:18:06 +08:00
parent 834a2c434a
commit 3a017cfacb
3 changed files with 11 additions and 1 deletions
+5 -1
View File
@@ -62,8 +62,12 @@ def _call(path: str, body_obj: dict[str, Any]) -> dict[str, Any]:
}
url = f"{settings.MT_CPS_HOST}{path}"
# 美团调用走 MT_CPS_PROXY(本机开发直连会 SSL EOF,必须走代理;线上留空=直连)。
# trust_env=False:不读进程环境的 HTTP_PROXY,只认配置,避免被错误/失效代理误导。
proxy = settings.MT_CPS_PROXY or None
try:
resp = httpx.post(url, content=body, headers=headers, timeout=settings.MT_CPS_TIMEOUT_SEC)
with httpx.Client(proxy=proxy, trust_env=False, timeout=settings.MT_CPS_TIMEOUT_SEC) as client:
resp = client.post(url, content=body, headers=headers)
except httpx.HTTPError as e:
logger.exception("[MT] http error calling %s", url)
raise MeituanCpsError(f"meituan http error: {e}") from e