Page MenuHomePhabricator

TypeError: BotPassword.__init__() takes 3 positional arguments but 12 were given
Closed, ResolvedPublicBUG REPORT

Description

Steps to replicate the issue:

  • Install/upgrade/downgrade to pywikibot 10.7.2 (current tip of branch stable) or 10.7.1
  • Configure pywikibot using the instructions from https://www.mediawiki.org/wiki/Manual:Pywikibot/BotPasswords (pywikibot/families/family_id_family.py, user-config.py, etc)
  • Use the following entry in the password file (generated using Special:BotPasswords, specifically Special:BotPasswords/AndrybakBot in this case):
('family_id', 'AndrybakBot', BotPassword('AndrybakBot', '11111111111111111111111111111111'))
  • Ensure we're not using tokens from previous login:
python pwb.py login -logout
  • Run:
python pwb.py login

What happens?:
After python pwb.py login

  File "<redacted>/core_stable/pywikibot/login.py", line 291, in readPassword
    entry = (entry[0], BotPassword(*entry[1]))
                       ^^^^^^^^^^^^^^^^^^^^^^
TypeError: BotPassword.__init__() takes 3 positional arguments but 12 were given
CRITICAL: Exiting due to uncaught exception TypeError: BotPassword.__init__() takes 3 positional arguments but 12 were given
  • I added some debug output to pywikibot/login.py just before the failing line, which gave me the following information:
    • entry[0] is family_id, which is whatever
    • but entry[1] is AndrybakBot, which is unexpected in the constructor of BotPassword

What should have happened instead?:
Successful logging in, something like:

Logging in to family_id:en as AndrybakBot@AndrybakBot
Logged in on family_id:en as AndrybakBot.

Execution time: 2 seconds

Other information

  • I've successfully used this password file since May 2021 without changes, and noticed the failure after upgrading pywikibot.
  • Cannot reproduce on version 10.7.0.
  • git blame pywikibot/login.py suggest that the root cause was the changes in T410753, commit fd7c23d (SEC: parse password lines as literals & update default PASS_BASENAME, 2025-11-22).

Event Timeline

Andrybak updated the task description. (Show Details)
Xqt triaged this task as High priority.Dec 9 2025, 10:17 AM

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

[pywikibot/core@master] Fix extracting password line

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

Xqt changed the task status from Open to In Progress.Dec 9 2025, 10:42 AM
Xqt claimed this task.

@Andrybak thank you for your helpful bug report. Are you able tor review my patch?

I applied the patch locally:

$ git log -1 --oneline 
970f1f086 (HEAD -> stable, tag: 10.7.2, origin/stable) [10.7.2] Add support for tokwiki and publish 10.7.2 release

$ git diff 
diff --git a/pywikibot/login.py b/pywikibot/login.py
index e7eb88cc7..eefb39d95 100644
--- a/pywikibot/login.py
+++ b/pywikibot/login.py
@@ -23,7 +23,6 @@ from pywikibot.comms import http
 from pywikibot.exceptions import APIError, NoUsernameError
 from pywikibot.tools import (
     PYTHON_VERSION,
-    deprecated,
     file_mode_checker,
     normalize_username,
 )
@@ -288,7 +287,7 @@ class LoginManager:
                 continue
 
             if botpassword:
-                entry = (entry[0], BotPassword(*entry[1]))
+                entry = (*entry[:-1], BotPassword(*entry[-1]))
 
             code, family, username, password = (
                 self.site.code, self.site.family.name)[:4 - entry_len] + entry
@@ -539,16 +538,6 @@ class ClientLoginManager(LoginManager):
 
         raise pywikibot.exceptions.APIError(code=status, info=fail_reason)
 
-    @deprecated("site.tokens['login']", since='8.0.0')
-    def get_login_token(self) -> str | None:
-        """Fetch login token.
-
-        .. deprecated:: 8.0
-
-        :return: login token
-        """
-        return self.site.tokens['login']
-
 
 class BotPassword:

and it works for me:

$ python pwb.py login -logout
Logged out of redacted:en.

Execution time: 2 seconds
$ python pwb.py login 
Logging in to redacted:en as AndrybakBot@AndrybakBot
Logged in on redacted:en as AndrybakBot.

Execution time: 2 seconds

As for code review, my experience with Python is limited, but the change on gerrit make sense to me too – the new code takes all elements of the tuple entry until the last one (slice until -1) as they are, and takes the last element of the tuple entry, unpacks it as a tuple, and uses them as as parameters to BotPassword. This applies to all cases when BotPassword is part of a line from the password file, for all variants (2, 3, or 4 items), which are listed the aforementioned page https://www.mediawiki.org/wiki/Manual:Pywikibot/BotPasswords

@Xqt, thank you for coming up with a fix so quickly!

Change #1216766 merged by Xqt:

[pywikibot/core@master] Fix extracting password line

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

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

[pywikibot/core@stable] [10.7.3] Publish Pywikibot 10.7.3 stable release

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

Change #1217116 merged by Xqt:

[pywikibot/core@stable] [10.7.3] Publish Pywikibot 10.7.3 stable release

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

The patch was backported to stable branch for PAWS and toolforge.