Sample code (simplified):
site = pywikibot.Site('ro', 'wikipedia')
page = pywikibot.Page(site, result['page_title'])
pywikibot.output(page.title())
if page.exists() and page.isRedirectPage():
page = page.getRedirectTarget()
elif not page.exists():
pass # DO stuffExpected outcome: get the redirect target or handle non-existent pages
Actual outcome:
Traceback (most recent call last):
File "pwb.py", line 420, in <module>
if not main():
File "pwb.py", line 415, in main
module)
File "pwb.py", line 113, in run_python_file
main_mod.__dict__)
File "./wikiro/robots/python/pywikipedia/localitati/create_shortcuts.py", line 80, in <module>
main()
File "./wikiro/robots/python/pywikipedia/localitati/create_shortcuts.py", line 64, in main
if page.exists() and page.isRedirectPage():
File "/home/andrei/pywikibot-core/pywikibot/page/__init__.py", line 717, in exists
raise InvalidPageError(self)Trying to debug, we add a print:
$ git diff pywikibot/page/__init__.py diff --git a/pywikibot/page/__init__.py b/pywikibot/page/__init__.py index ee06a0203..fa52faec5 100644 --- a/pywikibot/page/__init__.py +++ b/pywikibot/page/__init__.py @@ -714,6 +714,7 @@ class BasePage(ComparableMixin): """ with suppress(AttributeError): return self.pageid > 0 + print(self.pageid) raise InvalidPageError(self) @property
Sure enough, we had an AttributeError:
Traceback (most recent call last):
File "pwb.py", line 420, in <module>
if not main():
File "pwb.py", line 415, in main
module)
File "pwb.py", line 113, in run_python_file
main_mod.__dict__)
File "./wikiro/robots/python/pywikipedia/localitati/create_shortcuts.py", line 80, in <module>
main()
File "./wikiro/robots/python/pywikipedia/localitati/create_shortcuts.py", line 64, in main
if source_page.exists():
File "/home/andrei/pywikibot-core/pywikibot/page/__init__.py", line 717, in exists
print(self.pageid)
File "/home/andrei/pywikibot-core/pywikibot/page/__init__.py", line 261, in pageid
self.site.loadpageinfo(self)
File "/home/andrei/pywikibot-core/pywikibot/site/_apisite.py", line 1107, in loadpageinfo
self._update_page(page, query)
File "/home/andrei/pywikibot-core/pywikibot/site/_apisite.py", line 1081, in _update_page
for pageitem in query:
File "/home/andrei/pywikibot-core/pywikibot/data/api.py", line 2740, in __iter__
yield from super().__iter__()
File "/home/andrei/pywikibot-core/pywikibot/data/api.py", line 2582, in __iter__
prev_limit, new_limit, previous_result_had_data)
File "/home/andrei/pywikibot-core/pywikibot/data/api.py", line 2507, in _handle_query_limit
self.request[self.prefix + 'limit'] = str(new_limit)
AttributeError: 'PropertyGenerator' object has no attribute 'prefix'
CRITICAL: Exiting due to uncaught exception <class 'AttributeError'>Pywikibot version:
=== Pywikibot framework v7.0.0.dev0 -- Logging header === [80/1812] COMMAND: ['pwb.py', '-v'] DATE: 2021-11-02 13:35:29.761891 UTC VERSION: [https] r-pywikibot-core (28e31f9, g15398, 2021/09/21, 11:52:45, n/a) SYSTEM: <anonymized>