2017-10-09 131 views
0

我在节点上使用mwbot进行后续请求时出现此错误。如何使用mwbot请求Mediawiki使后续请求

response: 
    { login: 
     { result: 'Aborted', 
     reason: 'Cannot log in when using MediaWiki\\Session\\BotPasswordSessionProvider sessions' } } } 

我正在通过提供标题来阅读mediawiki中的页面。我认为每个请求都需要登录才能阅读,但似乎我错了,因为这个错误似乎在抱怨我已经登录了。但我不知道会话如何被读取或如何找出我已经登录或没有。

路线:

router.get('/wikipage/:title', function(req, res, next) { 
    let title = req.params.title; 

    const MWBot = require('mwbot'); 
    const wikiHost = "https://wiki.domain.com"; 
    let bot = new MWBot(); 
    let pageContent = "wiki page not created yet, please create"; 

    bot.login({ 
    apiUrl: wikiHost + "/api.php", 
    username: "[email protected]", 
    password: "xxxxx" 
    }).then((response) => { 
    console.log("logged in"); 
    return bot.read(title); 
    }).then((response) => { 
    for(let prop in response.query.pages) { 
     pageContent = response.query.pages[prop]['revisions'][0]['*']; 
     console.log("pageContent:", pageContent);  
     break; 
    } 

    res.json({ 
     data: pageContent 
    }); 

    }).catch((err) => { 
     // Could not login 
     console.log("error", err); 
    }); 

}); 

module.exports = router; 

回答

0

我相信你在浏览器中运行这一点,在这种情况下,浏览器需要的会话cookie小心处理。您可以通过document.cookie以常用方式查看。