【问题标题】:What is the reason for the error "Failed to decode JSON" in MediaWiki::API?MediaWiki::API 中出现“无法解码 JSON”错误的原因是什么?
【发布时间】:2012-06-26 23:58:53
【问题描述】:

我们在公司内部安装了私有的 MediaWiki。基于我们源代码的每日构建,我们使用 Perforce 标签更新 wiki,以便人们可以使用标记为简化流程的构建。我们尝试使用 MediaWiki::BotMediaWiki::API 在 Windows 服务器上使用 Perl 脚本自动执行此操作。

use MediaWiki::Bot;
use MediaWiki::API;

my $mw = MediaWiki::API->new();
$mw->{config}->{api_url} = 'http://somewiki/w/index.php/title#feature_List';

# log in to the wiki
$mw->login({
        lgname     => 'username',
        lgpassword => 'password'
          || die $mw->{error}->{code} . ': ' . $mw->{error}->{details};

          # get a list of articles in category
          my $articles = $mw->list({
                action  => 'query',
                list    => 'categorymembers',
                cmtitle => 'Category:Perl',
                cmlimit => 'max'
            }) || die $mw->{error}->{code} . ': ' . $mw->{error}->{details};

          # and print the article titles
          foreach (@{$articles}) {
            print "$_->{title}\n";
        }

输出:

2: Failed to decode JSON returned by http://vaporwiki/w/index.php/Executor#Execu
tor_Feature_List
Decoding Error:
malformed JSON string, neither array, object, number, string or atom, at charact
er offset 0 (before "<!DOCTYPE html PUBLI...") at C:/Perl/lib/MediaWiki/API.pm l
ine 398

Returned Data: <whole page data>

【问题讨论】:

  • 很难诊断您的安装问题,因为您忽略了透露任何相关信息,甚至没有透露您的 Perl 发行版(ActiveState Perl?)。 - 因为 Stack Overflow 在每个问题只有一个主题时效果最好,所以我已经删除了问题的那一部分,它仍然可以从 revisions 获得。复制这段文字和open a new one,以便妥善处理。

标签: perl mediawiki wikipedia-api mediawiki-api


【解决方案1】:

API URL 错误。试试http://vaporwiki/w/api.php

【讨论】:

  • 但是我们本地 wiki 中的链接看起来像 intranet/wiki/index.php/Main_Page
  • 这是 MediaWiki 的用户界面,但正如 daxim 所说,要访问 API,您必须改用 API 地址。
猜你喜欢
  • 1970-01-01
  • 2018-08-14
  • 2021-04-09
  • 1970-01-01
  • 2023-04-07
  • 2020-12-10
  • 2021-06-09
  • 2017-02-20
  • 1970-01-01
相关资源
最近更新 更多