Page MenuHomePhabricator

Sometimes a needed token is not set
Closed, ResolvedPublicBUG REPORT

Description

Steps to replicate the issue:

Run any script or tests which needs a token.

What happens?:

======================================================================
ERROR: test_watch (tests.page_tests.TestPageUserAction)
Test Page.watch, with and without unwatch enabled.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/runner/work/pywikibot/pywikibot/tests/page_tests.py", line 1029, in test_watch
    rv = userpage.watch(unwatch=True)
  File "/home/runner/work/pywikibot/pywikibot/pywikibot/page/_basepage.py", line 1377, in watch
    return self.site.watch(self, unwatch)
  File "/home/runner/work/pywikibot/pywikibot/pywikibot/site/_decorators.py", line 92, in callee
    return fn(self, *args, **kwargs)
  File "/home/runner/work/pywikibot/pywikibot/pywikibot/site/_apisite.py", line 2746, in watch
    results = req.submit()
  File "/home/runner/work/pywikibot/pywikibot/pywikibot/data/api/_requests.py", line 1088, in submit
    raise pywikibot.exceptions.APIError(**args)
pywikibot.exceptions.APIError: missingparam: The "token" parameter must be set.
[param: action=watch&titles=User%3APywikibot-test&unwatch=&assert=user&maxlag=5&format=json&token=;
 servedby: mw2317;
 help: See https://en.wikipedia.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.]

https://github.com/wikimedia/pywikibot/actions/runs/4638554224/jobs/8208471297

Other:
The reason is a badtoken response but the Requests._bad_token handler isn't able to solve it. The call of tokens = self.site.tokens.update_tokens(self._params['token']) gives an empty list.

Event Timeline

Xqt triaged this task as High priority.Apr 7 2023, 2:34 PM
Xqt changed the task status from Open to In Progress.Apr 7 2023, 3:57 PM
Xqt claimed this task.

Change 906740 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@master] [IMPR] Guess the last needed token key if the token is not found

https://gerrit.wikimedia.org/r/906740

Change 906740 merged by Xqt:

[pywikibot/core@master] [IMPR] Guess the last needed token key if the token is not found

https://gerrit.wikimedia.org/r/906740