【问题标题】:WWW::Wunderground::API Can't bless non-reference valueWWW::Wunderground::API 不能保佑非参考值
【发布时间】:2012-11-01 16:10:50
【问题描述】:

我想使用模块 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';

它给了我一个错误:

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

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

你能告诉我如何修理它吗?

提前谢谢你


与 Carp::Always:

不能祝福非参考价值在 /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

【问题讨论】:

  • 查看堆栈跟踪可能很有用。添加use Carp::Always; 并再次运行。
  • 我添加了 Carp::Always 并且我已经编辑了我的帖子

标签: json perl bless wunderground


【解决方案1】:

这是由于缺乏错误检查。以下意外返回undef

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

您可能希望通过以下方式查看获取的内容:

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");

您可以解决的响应中可能存在错误消息。例如,错误的 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"
        }
        }
}

【讨论】:

  • 谢谢。您的所有解决方案都有效。我的钥匙坏了,这是个问题。其次,您的解决方案也非常好。再次感谢
猜你喜欢
  • 1970-01-01
  • 2015-01-04
  • 1970-01-01
  • 2011-01-08
  • 1970-01-01
  • 2011-12-18
  • 2015-05-03
  • 2013-07-13
  • 2018-09-03
相关资源
最近更新 更多