I am trying to get the correct weather for a location so I can display it on a dashboard, for a users next trip. I have got the output working if I push into the server code the city, but this has the potential to cause issues if there happened to be more than 1 city with the same name.
As such I really want to use the longditude and latitude, but its coming up with a 400 error.
Here is the working code:-
api_key = "e6a2d01bf5c0234d0335082a7ecb1550"
root_url = "http://api.openweathermap.org/data/2.5/weather?"
city_name = city
lat = latitude
lon = longditude
url = f"{root_url}appid={api_key}&q={city_name}"
data = anvil.http.request(url,json=True)
print(data)
But if I change it to this:
api_key = "e6a2d01bf5c0234d0335082a7ecb1550"
root_url = "https://api.openweathermap.org/data/2.5/onecall?"
city_name = city
lat = latitude
lon = longditude
url = f"{root_url}lat={lat}lon={lon}&appid={api_key}"
data = anvil.http.request(url,json=True)
print(data)
Which is Openweathers example, here
https://api.openweathermap.org/data/2.5/onecall?lat={lat}&lon={lon}&exclude={part}&appid={API key}
I am getting a 400 error?
I tried the original query with the onecall URL and it gave the same 400 error.
I tried the lon/lat query with the original URL and it didnt like that either.