我想通过纬度和经度获得当前的天气数据。这是我的Python代码的一部分:
import requests
def get_weather(lat, lon):
return requests.get(f'http://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon},fr&appid=<MY API KEY>').json()
print(get_weather(96.95, 21.83))
它返回:
{"cod":"400","message":"96.95 is not a float"}
你知道什么是错的吗?
问题解决了!
问题是网址:
f'http://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon},fr&appid=<MY API KEY>'
正确的是:
f'http://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&appid=<MY API KEY>'