Giter Site home page Giter Site logo

Comments (7)

bruston avatar bruston commented on May 28, 2024

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.

bruston avatar bruston commented on May 28, 2024

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.

tejainece avatar tejainece commented on May 28, 2024

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.

tejainece avatar tejainece commented on May 28, 2024

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.

bruston avatar bruston commented on May 28, 2024

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.

tejainece avatar tejainece commented on May 28, 2024

Thanks. Let me know if you have any updates. I will do too.

from openweathermap.

briandowns avatar briandowns commented on May 28, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.