1

I am trying to have current weather data by latitude and longitude. Here is a part of my Python code:

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))

It returns this:

{"cod":"400","message":"96.95 is not a float"}

Do you know what's wrong ?

Rostan
  • 809
  • 9
  • 25

2 Answers2

1

Problem fixed !

The problem was the url:

f'http://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon},fr&appid=<MY API KEY>'

The correct one is:

f'http://api.openweathermap.org/data/2.5/weather?lat={lat}&lon={lon}&appid=<MY API KEY>'
Rostan
  • 809
  • 9
  • 25
1

This error message will occur when the provided latitude or longitude is out of range. A latitude of 96.95 is not within the valid latitude range.

Latitudes range from -90 to 90. Longitudes range from -180 to 180.

range source: https://stackoverflow.com/a/16743805/1816667

Marcy
  • 4,611
  • 2
  • 34
  • 52