Search code examples
pythonmediawikipywikibotwiktionary

How are you supposed to do admin/sysop actions with Pywikibot 8?


I have been using an outdated version of Pywikibot and Python 2 and finally got around to upgrading to Python 3 and Pywikibot 8. All support for "sysop" accounts seems to have been removed and there's no documentation I can find on how to work with two accounts, one of which is a bot account and one of which is a sysop account. The manual page https://www.mediawiki.org/wiki/Manual:Pywikibot/delete.py for the delete script, which requires sysop access, says you need your user-config.py to have the sysop account listed in place of the bot account. Does that mean I need to manually edit the file every time I need to switch between doing a regular bot action and a bot action requiring sysop access? There must be a better way. Trying to read through https://phabricator.wikimedia.org/T71283, people seem to have suggested the possibility of allowing multiple accounts to be listed for a given Wiki, but that doesn't seem to be implemented. It's hard for me to believe such basic functionality was simply removed with no replacement in mind.


Solution

  • How to use multiple accounts with Pywikibot?

    Introduction

    The dualism between bot account and sysop account was given up few years ago in favor of having multiple accounts instead e.g. sysop account, test account production account etc.

    Since Pywikibot 8 each account has his own cookie file which holds access information after logged in, see this patch which solves T324000. This means that is is no longer necessary to re-login after account switch. Also 2FA login (usally for sysop accounts) was introduced with Pywikibot 8.

    Global options

    Usually Pywikibot uses a user-config.py file to hold settings for a given user account. Read Account Settings section in documentation how to use it. With Pywkibot 7.7 a global -config option was introduced; this enables additional config files for other accounts, e.g. -config:mybot-config reads the settings from mybot-config.py instead of user-config.py.

    You can also determine the base directory using global -dir option and place the user-config.py file into a different folder.

    But there is another global option -user which enables using am account different from that user account which is registered in the user-config.py or any other setting file used with -config option.

    It is recommended to use the pwb wrapper script to eable global options with all private scripts (and some additional features).

    How to proceed

    • use -user global option to run a script with that given account, e.g.

      pwb -user:mybotaccount myscript --myoptions

      pwb -user:mysysopaccount myotherscript --otheroptions

    • use -config global option to run a script with that given config file, e.g.

      pwb -config:mybot-config myscript --myoptions

      pwb -user:mysysop-config myotherscript --otheroptions

    • use -dir global option load a config file from a different folder, e.g.

      pwb -dir:thispath myscript --myoptions

      pwb -user:thatpath myotherscript --otheroptions

    Note

    Different accounts may have different user rights. Pywikibot differentiates according to user rights and no longer according to group membership.