Configuring Pywikibot to use a wikimedia install's bot

61 views Asked by At

I have installed a wikimedia instance on a cloud server. I think the 'Family' is properly set up because I can, as an example, retrieve the content from the main page as:

# Set up the site
site = pywikibot.Site('en', 'mdswiki')  
# Get the main page
page = pywikibot.Page(site, 'Main Page')
# Print the content of the main page
print(page.text)

I'm doing this from inside a jupyter notebook.

But when I try to change some of the text and replace the page, it fails complaining about an undefined username

new_content = page.text.replace('Foo', 'Bar')
page.put(new_content, summary='Bot: Test edit')

throws:

OtherPageSaveError: Edit to page [[mdswiki:en:Main Page]] failed:
ERROR: username for mdswiki:en is undefined.
If you have a username for that site, please add a line to user config file (user_config.py) as follows:
usernames['mdswiki']['en'] = 'myUsername'

I think I did configure this. What I did:

Created a user, configured it as a bot, and created a bot password. This replied with The new password to log in with Golem@golem is u3g0l89eXXXredcatedXXXdcs3h. Please record this for future reference.

Then I have two files in C:\Anaconda3\envs\lamp\Lib\site-packages\pywikibot\scripts\

  1. user-config.py
mylang = 'en' 
usernames['mdswiki']['en'] = 'Golem'
password_file = "user-password.py"
  1. user-password.py
# This is an automatically generated file used to store
# 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 keys. This combination can only
# access the API, not the normal web interface.
#
# See https://www.mediawiki.org/wiki/Manual:Pywikibot/BotPasswords for more
# information.
('Golem', BotPassword('golem', 'u3g0lXXredactedXXXXXs3h'))

I have restarted the kernel to try to reload fresh configuration, but I keep getting this error. Should the two files be located in the scripts\ directory, or perhaps somewhere else? Or have i somehow misconfigured the name and password parameters? I'm quite at a loss - I tried multiple variations of the the Golem name and BotPassword etc.

1

There are 1 answers

0
user3556757 On

user-config.py and user-password.py needed to be in the same directory as the jupyter notebook where I was importing and using pywikibot module. I had incorrectly been keeping it in C:\Anaconda3\envs\lamp\Lib\site-packages\pywikibot\scripts\