Question

I would like to use module WWWW::Wunderground::API to download data with weather using JSON.

Here is my PERL script:

use WWW::Wunderground::API;

my $wun = new WWW::Wunderground::API(location=>'KIAD', api_key=>'my key');
print 'JSON source:'.$wun->json if $wun->api_type eq 'json';

It gives me an error:

Can't bless non-reference value at /usr/local/share/perl5/Hash/AsObject.pm line 82.

I cannot fix it up. I have been trying to update cpan and other modules but it gives no results.

Could you tell me how can I repair it?

Thank you in advance


with Carp::Always:

Can't bless non-reference value at /usr/local/share/perl5/Hash/AsObject.pm line 82 Hash::AsObject::AUTOLOAD('Hash::AsObject', undef) called at /usr/local/share/perl5/WWW/Wunderground/API.pm line 37 WWW::Wunderground::API::update('WWW::Wunderground::API=HASH(0x1e5b178)', 'KIAD') called at /home/xyz/workspace/WeatherTest/scr.pl line 4 eval {...} called at /home/xyz/workspace/WeatherTest/scr.pl line 4

Was it helpful?

Solution

It comes from a lack of error checking. The following unexpectedly returns undef:

JSON::Any->jsonToObj($json)->{current_observation}

You might want to have a look at what's getting fetched by using the following:

use LWP::Simple qw( get );
my $api_key  = 'my key';
my $location = 'KIAD';
print get("http://api.wunderground.com/api/$api_key/conditions/q/$location.json");

Perhaps there's an error message in the response you can address. For example, a bad API key would result in the following response:

{
        "response": {
                "version": "0.1"
                ,"termsofService": "http://www.wunderground.com/weather/api/d/terms.html"
                ,"features": {
                }
                ,
        "error": {
                "type": "keynotfound"
                ,"description": "this key does not exist"
        }
        }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top