test.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from config import Config
  2. conf = Config()
  3. import requests
  4. url = conf.weather_base_url
  5. headers = {"X-QW-Api-Key": conf.weather_api_key, "Accept-Encoding": "gzip, deflate, br"}
  6. chengdu = [
  7. 101270101, 101270102, 101270103, 101270104, 101270105,
  8. 101270106, 101270107, 101270108, 101270109, 101270110,
  9. 101270111, 101270112, 101270113, 101270114, 101270115,
  10. 101270116, 101270117, 101270118, 101270119, 101270120,
  11. 101270121
  12. ]
  13. beijing = [
  14. 101010100,
  15. 101010200,
  16. 101010300,
  17. 101010400,
  18. 101010500,
  19. 101010600,
  20. 101010700,
  21. 101010800,
  22. 101010900,
  23. 101011000,
  24. 101011100,
  25. 101011200,
  26. 101011300,
  27. 101011400,
  28. 101011500,
  29. 101011600,
  30. 101011700
  31. ]
  32. params = {
  33. 'location': '101270101'
  34. }
  35. def main():
  36. """手动验证天气 API;导入本文件不会发送请求。"""
  37. if not conf.weather_api_key or conf.weather_api_key.startswith("your_"):
  38. raise RuntimeError("请先在 .env 中填写自己的 QWEATHER_API_KEY。")
  39. if conf.weather_api_host == "your_qweather_host":
  40. raise RuntimeError("请先在 .env 中填写自己的 QWEATHER_API_HOST。")
  41. response = requests.get(url, headers=headers, params=params, timeout=15)
  42. response.raise_for_status()
  43. print(f"状态码: {response.status_code}")
  44. print("响应内容:")
  45. print(response.text)
  46. if __name__ == "__main__":
  47. main()