Page MenuHomePhabricator

claimit and harvest_template - Invalid token 'csrf'
Closed, ResolvedPublicBUG REPORT

Description

Running some script writing to wikidata, usually harvest_template.py or claimit.py or some own script

python pwb.py claimit "-cat:wikipedie:Rozcestníky "P31" "Q4167410"

What happens?:

>>> Afterparty <<<


>>> Q1770155 <<<
Adding P31 --> [[wikidata:Q4167410]]


>>> Aftershock <<<


>>> Against the Grain <<<
Exception in thread Put-Thread:
Traceback (most recent call last):
  File "C:\Python\Lib\threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "C:\Python\Lib\threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "D:\pwb\pywikibot\__init__.py", line 400, in async_manager
    request(*args, **kwargs)
  File "D:\pwb\pywikibot\page\_decorators.py", line 32, in handle
    func(self, *args, **kwargs)
  File "D:\pwb\pywikibot\page\_wikibase.py", line 908, in addClaim
    self.repo.addClaim(self, claim, bot=bot, **kwargs)
  File "D:\pwb\pywikibot\site\_decorators.py", line 93, in callee
    return fn(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\pwb\pywikibot\site\_datasite.py", line 379, in addClaim
    'token': self.tokens['csrf'],
             ~~~~~~~~~~~^^^^^^^^
  File "D:\pwb\pywikibot\site\_tokenwallet.py", line 60, in __getitem__
    raise KeyError(
KeyError: "Invalid token 'csrf' for user 'JAnDbot' on wikidata:wikidata wiki."


>>> Agassiz <<<

and no edit is made, script freeze when there is queue of 63 edits

What should have happened instead?:
script sjhould edit wikidata item.


sometimes, when I first run e.g newpage.py script have valid token and edits are made.

Details

Event Timeline

Xqt triaged this task as High priority.Jun 11 2026, 7:13 AM

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

[pywikibot/core@master] TokenWallet: Reload a single token if missing in the dict

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

@JAnD: Thank you for raising the issue again. The given patch should solve the problem. Maybe you are able to check it? I haven't checked the freezing queue issue yet but your bot looks outdated and there were improvement made in rPWBC04ffd99 and rPWBCb9245a4 (Pywikibot 11); Python 3.13+ is recommended.

@JAnD: Thank you for raising the issue again. The given patch should solve the problem. Maybe you are able to check it? I haven't checked the freezing queue issue yet but your bot looks outdated and there were improvement made in rPWBC04ffd99 and rPWBCb9245a4 (Pywikibot 11); Python 3.13+ is recommended.

I tested it on some scripts on two computers and seems to work

Change #1300722 merged by jenkins-bot:

[pywikibot/core@master] TokenWallet: Reload a single token if missing in the dict

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