mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-26 04:39:53 +01:00
update:显示天气接口错误信息
This commit is contained in:
parent
1988bced60
commit
5b7d613a35
1 changed files with 5 additions and 0 deletions
|
|
@ -110,6 +110,11 @@ WEATHER_CODE_MAP = {
|
||||||
def fetch_city_info(location, api_key, api_host):
|
def fetch_city_info(location, api_key, api_host):
|
||||||
url = f"https://{api_host}/geo/v2/city/lookup?key={api_key}&location={location}&lang=zh"
|
url = f"https://{api_host}/geo/v2/city/lookup?key={api_key}&location={location}&lang=zh"
|
||||||
response = requests.get(url, headers=HEADERS).json()
|
response = requests.get(url, headers=HEADERS).json()
|
||||||
|
if response.get("error") is not None:
|
||||||
|
logger.bind(tag=TAG).error(
|
||||||
|
f"获取天气失败,原因:{response.get('error', {}).get('detail')}"
|
||||||
|
)
|
||||||
|
return None
|
||||||
return response.get("location", [])[0] if response.get("location") else None
|
return response.get("location", [])[0] if response.get("location") else None
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue