Page MenuHomePhabricator

Fix "Fetching a token via "action=login" is deprecated" when authenticating via bot passwords
Closed, ResolvedPublic

Description

Currently when trying to login with botpassword, a warning message indicating "fetching a token via "action=login" is deprecated" will be shown, and an error message will be returned. The logic inside login_to_site function is to submit a login request (w/o "lgtoken" parameter) first, then perform a re-login. I thought probably we could move the code block of getting a login token to the position before submit a login request (inside that while True loop), which could fix such warning.

>>> import pywikibot
>>> site = pywikibot.Site('test', 'wikipedia', user='Crystal-bot')
>>> site.login()
WARNING: No user is logged in on site wikipedia:test
Logging in to wikipedia:test as Crystal-bot@botname
WARNING: API warning (main): 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. Use [[Special:ApiFeatureUsage]] to see usage of deprecated features by your application.
WARNING: API warning (login): Fetching a token via "action=login" is deprecated. Use "action=query&meta=tokens&type=login" instead.
ERROR: Received incorrect login token. Forcing re-login.
>>>

Event Timeline

Xqt triaged this task as High priority.EditedJun 4 2022, 11:48 AM
Xqt subscribed.

After all of your shell commands,

>>> import pywikibot
>>> site = pywikibot.Site('test', 'wikipedia', user='Crystal-bot')
>>> site.login()
WARNING: No user is logged in on site wikipedia:test
Logging in to wikipedia:test as Crystal-bot@botname
WARNING: API warning (main): 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. Use [[Special:ApiFeatureUsage]] to see usage of deprecated features by your application.
WARNING: API warning (login): Fetching a token via "action=login" is deprecated. Use "action=query&meta=tokens&type=login" instead.
ERROR: Received incorrect login token. Forcing re-login.
>>>

what is the result of these statements?:

>>> site.username()
>>> site.user() or site.user() is None

what is the result of these statements?:

>>> site.username()
>>> site.user() or site.user() is None
>>> site.username()
'Crystal-bot'
>>> site.user() or site.user() is None
'Crystal-bot'
>>> site.username()
'Crystal-bot'
>>> site.user() or site.user() is None
'Crystal-bot'

Thank you. That means your bot is logged in and there is only a warning thrown like in T137805. What is your

>>> site.version() ?

Thank you. That means your bot is logged in and there is only a warning thrown like in T137805. What is your

>>> site.version() ?

>>> site.version()
'1.39.0-wmf.14'

Same for Special:Version on testwiki.

Xqt lowered the priority of this task from High to Low.Jun 11 2022, 4:23 PM

Seems this is for BotPassword and T178061 is for client login.

Just a note that this warning is still happening:

Logging in to officewiki:officewiki as Officewikibot@toolforge
WARNING: API warning (main): 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. Use [[Special:ApiFeatureUsage]] to see usage of deprecated features by your application.
WARNING: API warning (login): Fetching a token via "action=login" is deprecated. Use "action=query&meta=tokens&type=login" instead.
ERROR: Received incorrect login token. Forcing re-login.

Runtime context:

$ webservice buildservice shell -- pwb --version
Pywikibot: [https] toolforge-repos-officewikibot-pywikibot (998aaa8, g1, 2023/11/17, 14:56:35, OUTDATED)
Release version: 8.5.1
setuptools version: 63.4.3
mwparserfromhell version: 0.6.5
wikitextparser version: n/a
requests version: 2.31.0
  cacerts: /app/.heroku/python/lib/python3.9/site-packages/certifi/cacert.pem
    certificate test: ok
Python: 3.9.18 (main, Aug 24 2023, 22:36:08)
[GCC 11.4.0]
PYWIKIBOT_DIR: Not set
PYWIKIBOT_DIR_PWB: /workspace/pywikibot/scripts
PYWIKIBOT_NO_USER_CONFIG: Not set
Config base dir: /workspace
Usernames for family 'officewiki':
        *: Officewikibot
bd808 renamed this task from Fix "Fetching a token via "action=login" is deprecated" to Fix "Fetching a token via "action=login" is deprecated" when authenticating via bot passwords.Nov 20 2023, 5:27 PM

Change 990720 had a related patch set uploaded (by Huji; author: Huji):

[pywikibot/core@master] Pass login token when using action=login

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

Change 990720 merged by jenkins-bot:

[pywikibot/core@master] Pass login token when using action=login

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