fix: avoid extra http client dependency
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import logging
|
||||
|
||||
import httpx
|
||||
import json
|
||||
from urllib import request
|
||||
|
||||
from app.core.config import settings
|
||||
|
||||
@@ -13,13 +13,16 @@ def send_wecom_text(content: str) -> bool:
|
||||
if not text or not webhook:
|
||||
return False
|
||||
try:
|
||||
response = httpx.post(
|
||||
payload = json.dumps({"msgtype": "text", "text": {"content": text[:3500]}}).encode("utf-8")
|
||||
req = request.Request(
|
||||
webhook,
|
||||
json={"msgtype": "text", "text": {"content": text[:3500]}},
|
||||
timeout=10.0,
|
||||
data=payload,
|
||||
headers={"Content-Type": "application/json"},
|
||||
method="POST",
|
||||
)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
with request.urlopen(req, timeout=10) as resp:
|
||||
body = resp.read().decode("utf-8", errors="ignore")
|
||||
data = json.loads(body or "{}")
|
||||
ok = int(data.get("errcode", -1)) == 0
|
||||
if not ok:
|
||||
logger.warning(f"WeCom bot send failed: {data}")
|
||||
|
||||
Reference in New Issue
Block a user