2012-06-26 49 views
0

我们在公司内部有私人MediaWiki安装。根据我们的源代码每日构建,我们使用Perforce标签更新wiki,以便人们可以使用标记为简化流程的构建。我们尝试使用MediaWiki::BotMediaWiki::API在Windows服务器上使用Perl脚本自动执行此操作。MediaWiki :: API中错误“无法解码JSON”的原因是什么?

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> 
+0

很难诊断您的安装问题,因为您忽略了揭示任何相关信息,甚至不包括您的Perl发行版(ActiveState Perl?)。 - 由于堆栈溢出在每个问题只有一个主题时效果最好,所以我删除了这部分问题,它仍然可以从[revisions](http://stackoverflow.com/posts/11217610/revisions)中获得。复制此文本并[打开一个新文件](http://stackoverflow.com/questions/ask),以便正确处理它。 – daxim

回答

5

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

+0

,但我们本地wiki中的链接看起来像 http://intranet/wiki/index.php/Main_Page – bicepjai

+2

这就是MediaWiki的用户界面,但正如daxim所说,对于API访问,您必须改用API地址。 – jpatokal

相关问题