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
'{"cod": 401, "message": "Invalid API key. Please see https://openweathermap.org/faq#error401 for more info."}'

浙公网安备 33010602011771号