Manual:Pywikibot/BotPasswords

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

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

Requirements

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

Configuration

 * Generate a bot password under Special:BotPasswords (or the corresponding page on another wiki):
 * Fill in a 'bot name', which is the suffix which will be added to your username. For example 'replace-on-tools'.
 * 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'.
 * You will receive a message like The new password to log in with Valhallasw@replace-on-tools is mysupersecretbotpassword Do not close this window until you saved the password in your password file (see below)
 * In the directory where your  is, create a file called , and make it unreadable for others
 * In the file user-password.py, add a line
 * In user-config.py, add the line
 * Run . Pywikibot should now login using your bot password:

Logging in to meta:meta as Valhallasw@replace-on-tools Logged in on meta:meta as Valhallasw.

password_file entries format
The entries in  should be tuples with 2, 3, or 4 items:
 * Used when the entry should only be used on a specific, e.g.   or.
 * Used when the entry should only be used on a specific  and , e.g.   and.
 * Used when the entry should only be used on a specific, e.g.   or.
 * Used when the entry should only be used on a specific  and , e.g.   and.
 * Used when the entry should only be used on a specific  and , e.g.   and.


 * Note: Entries that come later override those that come before them. For example if the password file contains
 * Then the BotPassword entry will be used for https://en.wikipedia.org/.
 * Then the BotPassword entry will be used for https://en.wikipedia.org/.