配置Pywikibot对接自建MediaWiki实例时的用户名未定义问题排查
问题:Pywikibot编辑MediaWiki页面提示用户名未定义
在云服务器上搭建了MediaWiki实例,确认Pywikibot的Family配置正常,可通过以下代码获取主页面内容:
# 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)
操作环境为Jupyter Notebook,但尝试编辑页面时(代码如下):
new_content = page.text.replace('Foo', 'Bar') page.put(new_content, summary='Bot: Test edit')
抛出错误:
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'
已创建机器人账户并配置BotPassword,得到提示:The new password to log in with Golem@golem is u3g0l89eXXXredcatedXXXdcs3h. Please record this for future reference.
随后在C:\Anaconda3\envs\lamp\Lib\site-packages\pywikibot\scripts\目录下创建了两个配置文件:
- user-config.py
mylang = 'en' usernames['mdswiki']['en'] = 'Golem' password_file = "user-password.py"
- 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'))
已重启内核重新加载配置,但错误依旧。请问是配置文件位置错误,还是用户名、密码参数配置有误?我尝试过多种Golem名称和BotPassword的写法,仍无法解决。
内容的提问来源于stack exchange,提问作者user3556757
相关产品推荐
相关产品推荐

