Script返回Pywikibot 7.2.0中没有用户登录到站点



最近我决定将Pywikibot更新到版本7,因为旧的API在Fandom wiki中已被弃用。非但没有解决问题,我最后还是用"没有用户登录"来砸自己的头。错误。我已经根据最新的Pywikibot文档正确配置了user-config.py和凭据。

Do you want to accept these changes? ([y]es, [N]o): y
WARNING: No user is logged in on site fkg:en
Traceback (most recent call last):
File "C:Python38libsite-packagespywikibotpage_decorators.py", line 32, in handle
func(self, *args, **kwargs)
File "C:Python38libsite-packagespywikibotpage_pages.py", line 1260, in _save
done = self.site.editpage(self, summary=summary, minor=minor,
File "C:Python38libsite-packagespywikibotsite_decorators.py", line 89, in callee
raise UserRightsError('User "{}" does not have required '
pywikibot.exceptions.UserRightsError: User "None" does not have required user right "edit"
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:FKGProcessing-mastersrcupdate_lists.py", line 36, in save
page.save(summary=comment or self.comment,
File "C:Python38libsite-packagespywikibotpage_pages.py", line 1248, in save
self._save(summary=summary, watch=watch, minor=minor, botflag=botflag,
File "C:Python38libsite-packagespywikibotpage_decorators.py", line 53, in wrapper
handle(func, self, *args, **kwargs)
File "C:Python38libsite-packagespywikibotpage_decorators.py", line 45, in handle
raise OtherPageSaveError(self, err)
pywikibot.exceptions.OtherPageSaveError: Edit to page [[Module:Equipment/Names]] failed:
User "None" does not have required user right "edit"
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:FKGProcessing-mastersrcupdate_lists.py", line 139, in <module>
run(sys.argv)
File "D:FKGProcessing-mastersrcupdate_lists.py", line 136, in run
bot.update()
File "D:FKGProcessing-mastersrcupdate_lists.py", line 108, in update
my.update_equipment_names()
File "D:FKGProcessing-mastersrcupdate_lists.py", line 76, in update_equipment_names
my.save(text, page)
File "D:FKGProcessing-mastersrcupdate_lists.py", line 38, in save
except pywikibot.LockedPage:
AttributeError: module 'pywikibot' has no attribute 'LockedPage'

下面是我想运行的脚本:https://github.com/HydroKirby/FKGProcessing/blob/master/src/update_lists.py

update_lists.py脚本看起来不对。第38行包含

except pywikibot.LockedPage:

但应该是

except pywikibot.exceptions.LockedPageError:

自Pywikibot 7。你必须先登录。有一个login.py脚本可以使用:https://doc.wikimedia.org/pywikibot/stable/utilities/scripts_ref.html#module-pywikibot.scripts.login。如果您使用Pywikibot作为站点包,则必须将bot更新到7.4版本,并调用以下脚本:

pwb.exe login

对于以前的Pywikibot 7.0版本,您可以使用:

pwb.exe shell
>>> site = pywikibot.Site()
>>> site.login()

后者也适用于IDLE或作为脚本,但您必须

import pywikibot

参考Site构造函数和login方法可用的参数文档:

  • https://doc.wikimedia.org/pywikibot/stable/api_ref/pywikibot.htm pywikibot.Site
  • https://doc.wikimedia.org/pywikibot/stable/api_ref/pywikibot.site.html pywikibot.site._apisite.APISite.login

最新更新