maxlath / wikibase-cli

read and edit a Wikibase instance from the command line
MIT License
223 stars 24 forks source link

Bad token error #176

Open PythonCoderAS opened 1 year ago

PythonCoderAS commented 1 year ago

While running a very long edit session (over 125k edits), the process terminated with this error:

{ badtoken: badtoken: Invalid CSRF token.
    at requestError (/mnt/nfs/labstore-secondary-tools-home/rpi2026f1/.local/lib/node_modules/wikibase-cli/node_modules/wikibase-edit/lib/request/parse_response_body.js:18:15)
    at module.exports (/mnt/nfs/labstore-secondary-tools-home/rpi2026f1/.local/lib/node_modules/wikibase-cli/node_modules/wikibase-edit/lib/request/parse_response_body.js:11:33)
    at process._tickCallback (internal/process/next_tick.js:68:7)
url: https://www.wikidata.org/w/api.php?action=wbsetdescription&format=json
response status: 200
response body: {"error":{"code":"badtoken","info":"Invalid CSRF token.","*":"See https://www.wikidata.org/w/api.php for API usage. Subscribe to the mediawiki-api-announce mailing list at <https://lists.wikimedia.org/postorius/lists/m
ediawiki-api-announce.lists.wikimedia.org/> for notice of API deprecations and breaking changes."},"servedby":"mw2287"}
  name: 'badtoken',
  statusCode: 500,
  statusMessage: undefined,
  headers:
   Headers {
     [Symbol(map)]:
      [Object: null prototype] {
        date: [ 'Thu, 06 Apr 2023 14:38:20 GMT' ],
        server: [ 'mw2287.codfw.wmnet' ],
        'x-content-type-options': [ 'nosniff' ],
        'mediawiki-api-error': [ 'badtoken' ],
        'x-frame-options': [ 'DENY' ],
        'content-disposition': [ 'inline; filename=api-result.json' ],
        'cache-control': [ 'private, must-revalidate, max-age=0' ],
        vary: [ 'Accept-Encoding' ],
        'content-length': [ '343' ],
        'content-type': [ 'application/json; charset=utf-8' ],
        age: [ '2' ],
        'x-cache': [ 'cp1077 pass, cp1083 pass' ],
        'x-cache-status': [ 'pass' ],
        'server-timing': [ 'cache;desc="pass", host;desc="cp1083"' ],
        'strict-transport-security': [ 'max-age=106384710; includeSubDomains; preload' ],
        'report-to':
         [ '{ "group": "wm_nel", "max_age": 604800, "endpoints": [{ "url": "https://intake-logging.wikimedia.org/v1/events?stream=w3c.reportingapi.network_error&schema_uri=/w3c/reportingapi/network_error/1.0.0" }] }' ],
        nel:
         [ '{ "report_to": "wm_nel", "max_age": 604800, "failure_fraction": 0.05, "success_fraction": 0.0}' ],
        'set-cookie':
         [ 'WMF-Last-Access=06-Apr-2023;Path=/;HttpOnly;secure;Expires=Mon, 08 May 2023 12:00:00 GMT',
           'WMF-Last-Access-Global=06-Apr-2023;Path=/;Domain=.wikidata.org;HttpOnly;secure;Expires=Mon, 08 May 2023 12:00:00 GMT',
           'GeoIP=US:::37.75:-97.82:v4; Path=/; secure; Domain=.wikidata.org' ],
        'x-client-ip': [ '185.15.56.66' ],
        'accept-ranges': [ 'bytes' ] } },
  body:
   { error:
      { code: 'badtoken',
        info: 'Invalid CSRF token.',
        '*':
         'See https://www.wikidata.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 de
precations and breaking changes.' },
     servedby: 'mw2287' },
  url:
   'https://www.wikidata.org/w/api.php?action=wbsetdescription&format=json',
context:
   { url:
      'https://www.wikidata.org/w/api.php?action=wbsetdescription&format=json',
     body:
      { error:
         { code: 'badtoken',
           info: 'Invalid CSRF token.',
           '*':
            'See https://www.wikidata.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: 'mw2287' } } }
maxlath commented 1 year ago

Hum, that's weird, it's suppose to try to get a new token when it gets this error. I tried to make the request function more resilient by retrying more times, and publish that patch in wikibase-cli v16.3.2. Hopefully that will be enough to fix the issue, but please do let me know if that happens again with the patched version.

Were you able to restart the batch session from where it crashed without too much troubles?

PythonCoderAS commented 1 year ago

Since the batch session was about 90% complete I decided the trouble of figuring out which items were complete was too much. This batch had over 125k items, so it would be a pain to figure out.

maxlath commented 1 year ago

Didn't the logs just above the error tell you the last successful edit?

PythonCoderAS commented 1 year ago

It did, but since the item list is so high, it's not an immediate priority to rerun the batch since all it was doing was setting descriptions in a language.