我正试着按经度和纬度来获取当前的天气数据。下面是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"}你知道怎么回事吗?
发布于 2019-10-24 15:02:35
当提供的纬度或经度超出范围时,将发生此错误消息。纬度96.95不在有效纬度范围内。
纬度范围从-90到90。经度范围从-180到180。 范围来源:https://stackoverflow.com/a/16743805/1816667
发布于 2017-12-23 13:42:18
问题解决了!
问题在于网址:
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>'https://stackoverflow.com/questions/47952691
复制相似问题