Comments (7)
It looks like you'll receive this error if you give CurentByName a name which the API cannot find since the endpoint will send back an error object instead of the expected response:
http://api.openweathermap.org/data/2.5/weather?q=idontexist
{"message":"Error: Not found city","cod":"404"}
It might be a good idea to get some better error handling for these cases instead of returning the error from the JSON decoder.
Update:
Stumbled on to this: https://openweathermap.desk.com/customer/portal/questions/9944207-list-of-expected-error-codes
Where it is stated that the error messages, or even the structure of them cannot be relied on. So it looks like the best you could do is check for http.StatusOk and that doesn't appear to be reliable either. :(
from openweathermap.
Seems like the openweathermap API is having some issues at the moment too, so if you're sure the place should exist, it may just be that. :)
from openweathermap.
The city seems to exist. For city Kungälv, I am getting error
Fetch error for city Kungälv: json: cannot unmarshal string into Go value of type int
I also get different errors for other cities. I will post them next message.
from openweathermap.
These are all the errors I am getting.
Fetch error for city Malmö: invalid character 'i' in literal false (expecting 'l')
Fetch error for city Uppsala: EOF
Fetch error for city Västerås: EOF
Fetch error for city Örebro: invalid character 'i' in literal false (expecting 'l')
Fetch error for city Helsingborg: EOF
Fetch error for city Täby: json: cannot unmarshal number into Go value of type openweathermap.CurrentWeatherData
Fetch error for city Växjö: json: cannot unmarshal number into Go value of type openweathermap.CurrentWeatherData
Fetch error for city Halmstad: json: cannot unmarshal number into Go value of type openweathermap.CurrentWeatherData
Fetch error for city Sundsvall: invalid character 'i' in literal false (expecting 'l')
Fetch error for city Luleå: invalid character 'i' in literal false (expecting 'l')
Fetch error for city Trollhättan: invalid character 'i' in literal false (expecting 'l')
Fetch error for city Östersund: invalid character 'i' in literal false (expecting 'l')
Fetch error for city Borlänge: EOF
Fetch error for city Tumba: invalid character 'i' in literal false (expecting 'l')
Fetch error for city Upplands Väsby: EOF
Fetch error for city Skellefteå: EOF
Fetch error for city Lidingö: invalid character 'i' in literal false (expecting 'l')
Fetch error for city Uddevalla: EOF
Fetch error for city Landskrona: invalid character 'i' in literal false (expecting 'l')
Fetch error for city Karlskoga: EOF
Fetch error for city Märsta: EOF
Fetch error for city Kungälv: json: cannot unmarshal string into Go value of type int
Fetch error for city Visby: EOF
Fetch error for city Vänersborg: json: cannot unmarshal number into Go value of type openweathermap.CurrentWeatherData
from openweathermap.
This demo program was able to get results but only after re-trying a few times (with various errors).
I'm getting intermittent errors when querying the API directly in the browser too:
failed to connect
500 /proxy/data/2.5/weather?q=portsmouth&
Or just no response. I guess we have to wait for it to settle down.
package main
import (
"fmt"
"log"
owm "github.com/briandowns/openweathermap"
)
func main() {
w, err := owm.NewCurrent("F", "en")
if err != nil {
log.Fatal(err)
}
if err = w.CurrentByName("Kungälv"); err != nil {
log.Fatal(err)
}
fmt.Printf("%#v\n", w)
}
[benjamin@inara weather]$ go run main.go
2015/03/13 17:02:36 invalid character 'i' in literal false (expecting 'l')
exit status 1
[benjamin@inara weather]$ go run main.go
&openweathermap.CurrentWeatherData{GeoPos:openweathermap.Coordinates{Longitude:11.98, Latitude:57.87}, Sys:openweathermap.Sys{Type:1, ID:5387, Message:0.0351, Country:"Sweden", Sunrise:1426224759, Sunset:1426266620}, Base:"cmc stations", Weather:[]openweathermap.Weather{openweathermap.Weather{ID:800, Main:"Clear", Description:"Sky is Clear", Icon:"01d"}}, Main:openweathermap.Main{Temp:44.56, TempMin:42.8, TempMax:47.3, Pressure:1035, Sea_level:0, Grnd_level:0, Humidity:33}, Wind:openweathermap.Wind{Speed:9.94, Deg:70}, Clouds:openweathermap.Clouds{All:0}, Dt:1426264275, ID:2698739, Name:"Kungälv", Cod:200, Unit:"F", Lang:"EN"}
from openweathermap.
Thanks. Let me know if you have any updates. I will do too.
from openweathermap.
Well, looks like the OWM API is fine again but I love to hear some ideas on how to update the package to handle stuff like this better. We can adjust to check return codes, return errors depending on which ones they might be, use error struct to unmarshal to if warranted, etc. Thoughts?
from openweathermap.
Related Issues (20)
- Pollution implementation seems to be out of date HOT 2
- Semantic versioning format is incorrect HOT 1
- In come cases uv index value in between 2.91 to 3.0 . HOT 1
- OpenWeather 3.0 API HOT 2
- Error upon non-existing places are unintuitive HOT 2
- Invalid data type of cod and message HOT 1
- Project being abandoned or no longer actively maintained? HOT 4
- Forecast search by zip HOT 1
- Rain and snow data missing from current? HOT 1
- [ISSUE] Error Marshaling Json Response HOT 1
- versioning is not correct for go mod HOT 3
- Add One Call API HOT 2
- Forcast5 not returning 5 day forcast HOT 2
- Requests still return invalid API key with code 401 HOT 2
- *byzip should not use int as datatype HOT 1
- UV Index API Deprecated HOT 1
- Please, change var iconUrl to "http://openweathermap.org/img/wn/%s"
- There is an error message of {"cod":"400","message":"wrong latitude"} HOT 2
- missing http part in all api urls HOT 3
- Inalid API key HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openweathermap.