WWW :: Wunderground :: API无法保佑非参考价值

Let*_*hat 3 perl json bless wunderground

我想使用模块WWWW :: Wunderground :: API使用JSON下载天气数据.

这是我的PERL脚本:

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';
Run Code Online (Sandbox Code Playgroud)

它给了我一个错误:

不能在/usr/local/share/perl5/Hash/AsObject.pm第82行祝福非参考值.

我无法修复它.我一直在尝试更新cpan和其他模块,但它没有给出任何结果.

你能告诉我怎么修理它?

先感谢您


与鲤鱼::总是:

无法在/usr/local/share/perl5/Hash/AsObject.pm第82行保佑非参考值Hash :: AsObject :: AUTOLOAD('Hash :: AsObject',undef)在/ usr/local/share中调用/perl5/WWW/Wunderground/API.pm第37行WWW :: Wunderground :: API :: update('WWW :: Wunderground :: API = HASH(0x1e5b178)','KIAD')在/ home/xyz/workspace调用/WeatherTest/scr.pl第4行eval {...}在/home/xyz/workspace/WeatherTest/scr.pl第4行调用

ike*_*ami 5

它来自缺乏错误检查.以下意外返回undef:

JSON::Any->jsonToObj($json)->{current_observation}
Run Code Online (Sandbox Code Playgroud)

您可能想要查看使用以下内容获取的内容:

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");
Run Code Online (Sandbox Code Playgroud)

也许在您可以解决的响应中存在错误消息.例如,错误的API密钥会导致以下响应:

{
        "response": {
                "version": "0.1"
                ,"termsofService": "http://www.wunderground.com/weather/api/d/terms.html"
                ,"features": {
                }
                ,
        "error": {
                "type": "keynotfound"
                ,"description": "this key does not exist"
        }
        }
}
Run Code Online (Sandbox Code Playgroud)