Manual:Pywikibot/BotPasswords

From MediaWiki.org
Jump to navigation Jump to search

As a simpler (but less secure) alternative to OAuth MediaWiki allows bot users to use BotPasswords to limit the permissions given to a bot.

When using BotPasswords each instance gets a login_name of the form <username>@<bot suffix> and a password. This combination can only access the API, not the normal web interface.

Requirements[edit]

  • The wiki where you want to use the bot needs MediaWiki > 1.27
  • In most installations, the client software should be configured to use https protocol.
  • Though logins may initially appear to work, the generated cookie appears incomplete and pywikibot actions relying on rights will fail. Refer to Phab:T150645.

Configuration[edit]

  1. Generate a bot password under Special:BotPasswords (or the corresponding page on another wiki):
    1. Fill in a 'bot name', which is the suffix which will be added to your username. For example 'replace-on-tools'.
    2. Grant the relevant rights. For most Pywikibot scripts High-volume editing, Edit existing pages and Create, edit, and move pages are enough. If you also want to upload files with the bot, include Upload new files and Upload, replace, and move files. Leave the usage restrictions as-is. Click 'create'.
    3. You will receive a message like The new password to log in with Valhallasw@my-botpassword-name is mysupersecretbotpassword Do not close this window until you saved the password in your password file (see below)
using generate_user_files.py script
  1. This script can manage for you the creation of a user-password.py file. Simply run python generate_user_files.py, and follow the prompts. After the choice of a wiki, and entering your username, you'll be able to enter the name/pass couple created on Special:BotPasswords at the previous step. The name is the one you've chosen, the pass is the one given by the website.
or creating user-password.py file manually
  1. In the directory where your user-config.py is, create a file called user-password.py, and make it unreadable for others (chmod 600 user-password.py)
  2. In the file user-password.py, add a line (u'Valhallasw', BotPassword(u'my-botpassword-name', u'mysupersecretbotpassword'))
  3. In user-config.py, add the line password_file = "user-password.py"
check that config is working
  1. Run python pwb.py login. Pywikibot should now automatically login using your bot password:
Logging in to meta:meta as Valhallasw@my-botpassword-name
Logged in on meta:meta as Valhallasw.

password_file entries format[edit]

The entries in user-password.py should be tuples with 2, 3, or 4 items:

  • ('Username', BotPassword('BotName', 'Password'))
  • ('FamilyName', 'Username', BotPassword('BotName', 'Password'))
    Used when the entry should only be used on a specific FamilyName, e.g. wikipedia or wikisource.
  • ('SiteCode', 'FamilyName', 'Username', BotPassword('BotName', 'Password'))
    Used when the entry should only be used on a specific FamilyName and SiteCode, e.g. wikipedia and en.
Note
Entries that come later override those that come before them. For example if the password file contains
('Username', 'AccountPassword')
('en', 'wikipedia', 'Username', BotPassword('BotName', 'Password'))
Then the BotPassword entry will be used for https://en.wikipedia.org/ .

See also[edit]