kanasimi / wikiapi

JavaScript MediaWiki API for node.js
https://kanasimi.github.io/wikiapi/
BSD 3-Clause "New" or "Revised" License
47 stars 5 forks source link

"Too many values supplied for parameter \"pageids\". The limit is 50." #52

Closed hugolpz closed 2 years ago

hugolpz commented 2 years ago

Given the code :

const Wikiapi= require('wikiapi');
const logins = require('./logins.js');

// Login credentials from .login*.js
var USER = logins.commons.user,
    PASS = logins.commons.pass,
    API  = logins.commons.api;

(async () => {
    // Connect
    var targetwiki = new Wikiapi;
    await targetwiki.login(USER, PASS, API);
    console.log(`Username ${USER.split('@')[0]} is connected !`);

/* *************************************************************** */
/* CORE ACTION(S) HERE : HACK ME ! ******************************* */
    // List of categories
    var categories = (await targetwiki.category_tree('Lingua_Libre_pronunciation', { depth: 1, cmtype: 'subcat', get_flated_subcategories: true })).flated_subcategories;
    keys=Object.keys(categories)
    console.log(keys.length+' keys :\n '+JSON.stringify(keys))

/* END CORE ****************************************************** */
/* *************************************************************** */
})();

Update cejs done:

~/Documents/WikiapiJS-Eggs$ node GitHub.updater.node.js
Read the latest version from cache file CeJS-master.version.json
Get the infomation of latest version of CeJS...
Already have the latest version: 2022-01-05T08:20:26Z

Due to .category_tree(), the script prints the following warning message, while the script continue to work fine :

/Documents/WikiapiJS-Eggs$ node wiki-category_tree-many.js 
get_API_parameters: Cache commonswiki: path=query+siteinfo
Username ShufaBot is connected !
get_list: Unknown response: [{"error":{"code":"toomanyvalues","info":"Too many values supplied for parameter \"pageids\". The limit is 50.","limit":50,"lowlimit":50,"highlimit":500,"*":"See https://commons.wikimedia.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/postorius/lists/mediawiki-api-announce.lists.wikimedia.org/> for notice of API deprecations and breaking changes."},"servedby":"mw1363"}]
Trace: {
  error: {
    code: 'toomanyvalues',
    info: 'Too many values supplied for parameter "pageids". The limit is 50.',
    limit: 50,
    lowlimit: 50,
    highlimit: 500,
    '*': 'See https://commons.wikimedia.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/postorius/lists/mediawiki-api-announce.lists.wikimedia.org/> for notice of API deprecations and breaking changes.'
  },
  servedby: 'mw1363'
}
    at wiki_API_list_callback (/home/yug/Documents/WikiapiJS-Eggs/node_modules/wikiapi/node_modules/cejs/application/net/wiki/list.js:1075:13)
    at wiki_API_next_list_callback (/home/yug/Documents/WikiapiJS-Eggs/node_modules/wikiapi/node_modules/cejs/application/net/wiki/task.js:571:16)
    at /home/yug/Documents/WikiapiJS-Eggs/node_modules/wikiapi/node_modules/cejs/application/net/wiki/list.js:587:5
    at check_session_badtoken (/home/yug/Documents/WikiapiJS-Eggs/node_modules/wikiapi/node_modules/cejs/application/net/wiki/query.js:189:4)
    at XMLHttp_handler (/home/yug/Documents/WikiapiJS-Eggs/node_modules/wikiapi/node_modules/cejs/application/net/wiki/query.js:687:4)
    at IncomingMessage.<anonymous> (/home/yug/Documents/WikiapiJS-Eggs/node_modules/wikiapi/node_modules/cejs/application/net/Ajax.js:2265:6)
    at IncomingMessage.emit (node:events:402:35)
    at endReadableNT (node:internal/streams/readable:1340:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21)
for_category_info_list: [object Object]
^Cpth 2/1: 17/131 Lingua Libre pronunciation-bdu: 0 item(s).    evels left)  
kanasimi commented 2 years ago

Wish you a happy new year holiday 😸 Try forcing update of cejs via node GitHub.updater.node.js. See https://github.com/kanasimi/CeJS/issues/13

kanasimi commented 2 years ago

Hi. For https://github.com/hugolpz/WikiapiJS-Eggs/blob/main/wiki-download_by_root_category-many.js You may try this:

// PURPOSE: Script to upload targets using an external data file.
// Run: $node wiki-upload-many.js
const fs = require('fs');
const Wikiapi= require('wikiapi');
const logins = require('./logins.js');

(async () => {
    // Connect
    var targetwiki = new Wikiapi;
    // Login credentials from .login*.js
    await targetwiki.login({user_name:logins.commons.user_name, password:logins.commons.pass, API_URL:logins.commons.api});
    console.log(`User ${logins.commons.user_name.split('@')[0]} is connected !`);

/* *************************************************************** */
/* CORE ACTION(S) HERE : HACK ME ! ******************************* */
    // Settings
    var localDirectory = './downloads/',
        masterCategory = 'Lingua_Libre_pronunciation';

    await targetwiki.download(targetwiki.to_namespace(masterCategory, 'Category'), { directory: localDirectory });
/* END CORE ****************************************************** */
/* *************************************************************** */
})();

You may also change the format in logins.js so you can use await targetwiki.login(logins.commons);

hugolpz commented 2 years ago

Thanks ! Issue was fixed by your code and me updating the package.