openweathermap API出错

问题描述 投票:0回答:1

我想通过纬度和经度获得当前的天气数据。这是我的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"}

你知道什么是错的吗?

python python-3.x weather-api openweathermap
1个回答
0
投票

问题解决了!

问题是网址:

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>'
© www.soinside.com 2019 - 2024. All rights reserved.