ARTICLE DETAIL

建站实战干货

来自一线的建站与推广经验沉淀,每一条都经过真实交付验证。

aaaa

2026/8/6 23:18:04 拓冰建站 浏览量
aaaa
"""
https://openweathermap.org/api
https://www.openweathermap.org/current、https://openweathermap.org/current#multi 文档(parameters)

unknowspeople1@gmail.com
"""
import json
import os

import requests

def get_weather(loc):
url = "https://api.openweathermap.org/data/2.5/weather"

params = {
"q": loc,
"appid": os.getenv("WEATHER_API_KEY"), # api_key
"units": "metric",
"lang": "zh_cn",
}

print("WEATHER_API_KEY", os.getenv("WEATHER_API_KEY"))

response = requests.get(url, params=params)

data = response.json()
return json.dumps(data, ensure_ascii=False)

 

 

WEATHER_API_KEY 499ac28c8d1a08d75db98cb919044bea
'{"cod": 401, "message": "Invalid API key. Please see https://openweathermap.org/faq#error401 for more info."}'