Langchain-Chatchat/libs/chatchat-server/chatchat/server/agent/tools_factory/test.py

21 lines
738 B
Python

import requests
import json
url = f"https://api.seniverse.com/v3/weather/now.json?key=SCXuHjCcMZfxWOy-R&location=合肥&language=zh-Hans&unit=c"
print(f"url:{url}")
response = requests.post(url,proxies={"http": None, "https": None})
print(f"response.text:{response.text}")
# 检查响应状态码
if response.status_code == 200:
try:
response.encoding = 'utf-8'
# 尝试将响应内容解析为 JSON
data = response.json() # 转换为 Python 字典
print(f"JSON Response:{data}")
except requests.exceptions.JSONDecodeError:
print("The response is not a valid JSON.")
else:
print(f"Request failed with status code: {response.status_code}")
print(f"Raw Response: {response.text}")