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