switch_global.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import httpx
  2. base_url_list = [
  3. "http://192.168.31.201:58001",
  4. "http://192.168.31.201:58002",
  5. "http://192.168.31.201:58003",
  6. "http://192.168.31.201:58004",
  7. "http://192.168.31.201:58005",
  8. "http://192.168.31.201:58006",
  9. "http://192.168.31.201:58007",
  10. "http://192.168.31.201:58008",
  11. "http://192.168.31.201:58009",
  12. "http://192.168.31.201:58010",
  13. ]
  14. for base_url in base_url_list:
  15. key = "/api/configs"
  16. url = base_url + key
  17. headers = {
  18. "accept": "application/json, text/plain, */*",
  19. "accept-encoding": "gzip, deflate, br, zstd",
  20. "accept-language": "zh-CN,zh",
  21. "connection": "keep-alive",
  22. "content-type": "application/json",
  23. "host": "localhost:17888",
  24. "origin": base_url,
  25. "referer": base_url,
  26. "sec-ch-ua": '"Not A(Brand";v="8", "Chromium";v="132", "Brave";v="132"',
  27. "sec-ch-ua-mobile": "?0",
  28. "sec-ch-ua-platform": '"macOS"',
  29. "sec-fetch-dest": "empty",
  30. "sec-fetch-mode": "cors",
  31. "sec-fetch-site": "same-origin",
  32. "sec-gpc": "1",
  33. "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36",
  34. }
  35. # 请求体数据
  36. data = {"mode": "Global"} # 替换为实际的请求数据
  37. # 使用 httpx 发送 PATCH 请求
  38. try:
  39. with httpx.Client() as client:
  40. response = client.patch(url, headers=headers, json=data)
  41. if response.status_code == 204:
  42. print(f"{base_url} 请求成功,无返回内容(204 No Content)")
  43. else:
  44. print("响应内容:", response.text)
  45. except httpx.RequestError as exc:
  46. print(f"请求失败: {exc}")