Page MenuHomePhabricator

replace.py: uncaught exception <class 'StopIteration'>
Closed, ResolvedPublic

Description

Command line:

python pwb.py replace -fix:HTML -site:wikinews:ar -page:User_talk:Madedy

Output:

Retrieving 1 pages from wikinews:ar.

0 pages read
0 pages written
0 pages skipped
Execution time: 1 seconds
Script terminated by exception:

ERROR: StopIteration:
Traceback (most recent call last):
  File "C:\Users\Mohammed\core\pwb.py", line 363, in <module>
    if not main():
  File "C:\Users\Mohammed\core\pwb.py", line 355, in main
    run_python_file(filename,
  File "C:\Users\Mohammed\core\pwb.py", line 74, in run_python_file
    exec(compile(source, filename, 'exec', dont_inherit=True),
  File ".\scripts\replace.py", line 1098, in <module>
    main()
  File ".\scripts\replace.py", line 1090, in main
    bot.run()
  File "C:\Users\Mohammed\core\pywikibot\bot.py", line 1495, in run
    self.treat(page)
  File ".\scripts\replace.py", line 678, in treat
    original_text = page.text
  File "C:\Users\Mohammed\core\pywikibot\page\__init__.py", line 560, in text
    return self.get(get_redirect=True)
  File "C:\Users\Mohammed\core\pywikibot\tools\__init__.py", line 1642, in wrapper
    return obj(*new_args, **new_kwargs)
  File "C:\Users\Mohammed\core\pywikibot\page\__init__.py", line 434, in get
    return self.latest_revision.text
  File "C:\Users\Mohammed\core\pywikibot\page\__init__.py", line 547, in latest_revision
    return next(self.revisions(content=True, total=1))
StopIteration
CRITICAL: Exiting due to uncaught exception <class 'StopIteration'>

Notes:

Request:

  • Please make the bot skip such pages (i.e. not break the bot run) when it encounters such pages. Thank you.

Event Timeline

A page that exits but has no history

This is strange and I am not sure what we should do here. Seems this is an issue for MediaWiki itself.

We could raise a kind of NoPage Error here. Do you have a proposal how to solve it?

A page that exits but has no history

This is strange and I am not sure what we should do here. Seems this is an issue for MediaWiki itself.

We could raise a kind of NoPage Error here. Do you have a proposal how to solve it?

Currently the bot run stops when it encounters such pages (when running on a whole namespace, for example). My request is to make the bot skip such pages and continue its run normally. I will update the task description accordingly.

Xqt triaged this task as Medium priority.Apr 16 2021, 10:03 AM

Command line:

python pwb.py fixing_redirects -lang:arz -start:Template:!

Output:

Script terminated by exception:

ERROR: StopIteration:
Traceback (most recent call last):
  File "C:\Users\Mohammed\core\pwb.py", line 364, in <module>
    if not main():
  File "C:\Users\Mohammed\core\pwb.py", line 356, in main
    run_python_file(filename,
  File "C:\Users\Mohammed\core\pwb.py", line 74, in run_python_file
    exec(compile(source, filename, 'exec', dont_inherit=True),
  File ".\scripts\fixing_redirects.py", line 232, in <module>
    main()
  File ".\scripts\fixing_redirects.py", line 226, in main
    bot.run()
  File "C:\Users\Mohammed\core\pywikibot\bot.py", line 1495, in run
    self.treat(page)
  File "C:\Users\Mohammed\core\pywikibot\bot.py", line 1774, in treat
    self.treat_page()
  File ".\scripts\fixing_redirects.py", line 163, in treat_page
    newtext = self.current_page.text
  File "C:\Users\Mohammed\core\pywikibot\page\__init__.py", line 560, in text
    return self.get(get_redirect=True)
  File "C:\Users\Mohammed\core\pywikibot\tools\__init__.py", line 1667, in wrapper
    return obj(*new_args, **new_kwargs)
  File "C:\Users\Mohammed\core\pywikibot\page\__init__.py", line 434, in get
    return self.latest_revision.text
  File "C:\Users\Mohammed\core\pywikibot\page\__init__.py", line 547, in latest_revision
    return next(self.revisions(content=True, total=1))
StopIteration
CRITICAL: Exiting due to uncaught exception <class 'StopIteration'>

Output of version.py:

Pywikibot: [https] r-pywikibot-core (f2c1be5, g14694, 2021/04/18, 17:40:50, master)
Release version: 6.1.1.dev0
requests version: 2.25.1
    certificate test: ok
Python: 3.9.4 (tags/v3.9.4:1f2e308, Apr  4 2021, 13:27:16) [MSC v.1928 64 bit (AMD64)]

So, @Xqt, could you, please, make the two scripts replace.py and fixing_redirects.py skip such pages without crashing? We have a bunch of such pages on Arabic wikis and it is painful for me to restart the bot every time it crashes. Thanks.

It’s not as easy as it looks The main Page attributes require a version history and all the dependencies must be investigated carefully.

Change 684118 had a related patch set uploaded (by Xqt; author: Xqt):

[pywikibot/core@master] [FEAT] skip InvalidPageError in replace.py and fixing_redirects.py

https://gerrit.wikimedia.org/r/684118

Change 684118 merged by jenkins-bot:

[pywikibot/core@master] [FEAT] skip InvalidPageError in replace.py and fixing_redirects.py

https://gerrit.wikimedia.org/r/684118