我在云服务器上安装了一个维基媒体实例。我认为“家庭”设置正确,因为作为示例,我可以从主页检索内容,如下所示:
# 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 笔记本中执行此操作。
但是当我尝试更改一些文本并替换页面时,它无法抱怨未定义的用户名
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'
我想我确实配置了这个。我做了什么:
创建了一个用户,将其配置为机器人,并创建了机器人密码。这回复了
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'))
我已重新启动内核以尝试重新加载新配置,但我不断收到此错误。这两个文件应该位于
scripts\
目录中,还是其他地方?或者我是否以某种方式错误配置了名称和密码参数?我很茫然 - 我尝试了 Golem 名称和 BotPassword 等的多种变体。
user-config.py
和 user-password.py
需要与我导入和使用 pywikibot 模块的 jupyter 笔记本位于同一目录中。我错误地把它放在了C:\Anaconda3\envs\lamp\Lib\site-packages\pywikibot\scripts\