demo_send_gotify.py 763 B

123456789101112131415161718192021222324252627282930
  1. # -*- coding: utf-8 -*-
  2. import httpx
  3. # Gotify服务器地址
  4. gotify_url = "https://gotify.erhe.top/message?token=A9KF--mx_12PjSu"
  5. # 要发送的消息内容
  6. message = {
  7. "message": "测试消息",
  8. "title": "测试标题",
  9. "priority": 5
  10. }
  11. async def send_message():
  12. async with httpx.AsyncClient() as client:
  13. try:
  14. response = await client.post(gotify_url, json=message)
  15. if response.status_code == 200:
  16. print("消息发送成功")
  17. else:
  18. print(f"消息发送失败,状态码: {response.status_code}")
  19. except httpx.RequestException as e:
  20. print(f"请求出现异常: {e}")
  21. if __name__ == "__main__":
  22. import asyncio
  23. asyncio.run(send_message())