lib_to_ws.py 753 B

12345678910111213141516171819202122232425262728
  1. import requests
  2. import json
  3. import config
  4. NOTIFY_URL = config.config["NOTIFY_URL"]
  5. def send_action_ws(action_type, action_content):
  6. # 定义要发送的数据
  7. data = {"type": action_type, "content": action_content}
  8. # 将数据转换为 JSON 格式
  9. json_data = json.dumps(data)
  10. # 设置请求头部
  11. headers = {
  12. "Content-Type": "application/json"
  13. }
  14. # 发送 POST 请求
  15. response = requests.post(NOTIFY_URL, data=json_data, headers=headers)
  16. # 检查响应状态码
  17. if response.status_code == 200:
  18. # 打印响应内容
  19. print("发送语义结果到websocket服务成功")
  20. else:
  21. print("发送语义结果到websocket服务失败,Error http code:", response.status_code)