Page MenuHomePhabricator

commonscat.py: uncaught exception: InvalidTitle: '{{PAGENAME}}' contains illegal char(s) '{'
Closed, ResolvedPublic

Description

Command line:

python3 pwb.py commonscat -lang:ary -start:!

Output:

Retrieving 1 pages from wikipedia:ary.


>>> أحلاف <<<

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

ERROR: InvalidTitle: '{{PAGENAME}}' contains illegal char(s) '{'
Traceback (most recent call last):
  File "pwb.py", line 363, in <module>
    if not main():
  File "pwb.py", line 358, in main
    file_package)
  File "pwb.py", line 75, in run_python_file
    main_mod.__dict__)
  File "./scripts/commonscat.py", line 561, in <module>
    main()
  File "./scripts/commonscat.py", line 555, in main
    bot.run()
  File "/mnt/nfs/labstore-secondary-tools-home/meno25/core/pywikibot/bot.py", line 1487, in run
    self.treat(page)
  File "/mnt/nfs/labstore-secondary-tools-home/meno25/core/pywikibot/bot.py", line 1766, in treat
    self.treat_page()
  File "./scripts/commonscat.py", line 316, in treat_page
    commonscatLink = self.find_commons_category(page)
  File "./scripts/commonscat.py", line 417, in find_commons_category
    return self.findCommonscatLink(page)
  File "./scripts/commonscat.py", line 385, in findCommonscatLink
    commonscatLink[1])
  File "./scripts/commonscat.py", line 464, in checkCommonscatLink
    if not commonsPage.exists():
  File "/mnt/nfs/labstore-secondary-tools-home/meno25/core/pywikibot/page/__init__.py", line 775, in exists
    return self.pageid > 0
  File "/mnt/nfs/labstore-secondary-tools-home/meno25/core/pywikibot/page/__init__.py", line 292, in pageid
    self.site.loadpageinfo(self)
  File "/mnt/nfs/labstore-secondary-tools-home/meno25/core/pywikibot/page/__init__.py", line 228, in site
    return self._link.site
  File "/mnt/nfs/labstore-secondary-tools-home/meno25/core/pywikibot/page/__init__.py", line 6010, in site
    self.parse()
  File "/mnt/nfs/labstore-secondary-tools-home/meno25/core/pywikibot/page/__init__.py", line 5965, in parse
    '%r contains illegal char(s) %r' % (t, m.group(0)))
pywikibot.exceptions.InvalidTitle: '{{PAGENAME}}' contains illegal char(s) '{'
CRITICAL: Exiting due to uncaught exception <class 'pywikibot.exceptions.InvalidTitle'>

Problem:

  • When running the script commonscat.py, the bot crashes when encountering the above error.
  • This is annoying as I have to manually restart the bot again.

Notes:

Request:

Please implement the same fix for commonscat.py (i.e. make the bot skip the page in this case instead of crashing). Thank you.

Version information:

Pywikibot: [https] r-pywikibot-core (fae6c25, g13693, 2020/11/11, 11:39:36, master)
Release version: 5.2.0.dev0
requests version: 2.21.0
  cacerts: /etc/ssl/certs/ca-certificates.crt
    certificate test: ok
Python: 3.5.3 (default, Jul  9 2020, 13:00:10)
[GCC 6.3.0 20170516]

Event Timeline

Xqt triaged this task as Medium priority.Nov 11 2020, 6:07 PM
Xqt subscribed.

@Meno25: you are the perfect beta-tester 😉

@Meno25: you are the perfect beta-tester 😉

Thank you ❤😊😊

@Meno25: you are the perfect beta-tester 😉

Thank you ❤😊😊

Hi again, @Xqt Could you, please, make commonscat.py run similarly to fixing_redirects.py?
(i.e. the bot should skip the page and not crash when encountering such exception)
I use commonscat.py a lot these days, and as usual, I need to save the time of manually restarting the bot each time it crashes.
This is a fresh output of both scripts:

fixing_redirects.py:

python pwb.py fixing_redirects -site:wikipedia:ary -page:"أحلاف"
Retrieving 1 pages from wikipedia:ary.

>>> أحلاف <<<
No changes were needed on [[أحلاف]]

1 pages read
0 pages written
0 pages skipped
Execution time: 2 seconds
Read operation time: 2.0 seconds
Script terminated successfully.

commonscat.py:

python pwb.py commonscat -site:wikipedia:ary -page:"أحلاف"
Retrieving 1 pages from wikipedia:ary.

>>> أحلاف <<<

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

ERROR: InvalidTitleError: '{{PAGENAME}}' contains illegal char(s) '{'
Traceback (most recent call last):
  File "C:\Users\Mohammed\Downloads\core\pwb.py", line 365, in <module>
    if not main():
  File "C:\Users\Mohammed\Downloads\core\pwb.py", line 357, in main
    run_python_file(filename,
  File "C:\Users\Mohammed\Downloads\core\pwb.py", line 73, in run_python_file
    exec(compile(source, filename, 'exec', dont_inherit=True),
  File ".\scripts\commonscat.py", line 557, in <module>
    main()
  File ".\scripts\commonscat.py", line 551, in main
    bot.run()
  File "C:\Users\Mohammed\Downloads\core\pywikibot\bot.py", line 1533, in run
    self.treat(page)
  File "C:\Users\Mohammed\Downloads\core\pywikibot\bot.py", line 1814, in treat
    self.treat_page()
  File ".\scripts\commonscat.py", line 318, in treat_page
    commonscatLink = self.find_commons_category(page)
  File ".\scripts\commonscat.py", line 412, in find_commons_category
    return self.findCommonscatLink(page)
  File ".\scripts\commonscat.py", line 385, in findCommonscatLink
    checkedCommonscat = self.checkCommonscatLink(commonscatLink[1])
  File ".\scripts\commonscat.py", line 457, in checkCommonscatLink
    if not commonsPage.exists():
  File "C:\Users\Mohammed\Downloads\core\pywikibot\page\__init__.py", line 710, in exists
    return self.pageid > 0
  File "C:\Users\Mohammed\Downloads\core\pywikibot\page\__init__.py", line 258, in pageid
    self.site.loadpageinfo(self)
  File "C:\Users\Mohammed\Downloads\core\pywikibot\page\__init__.py", line 195, in site
    return self._link.site
  File "C:\Users\Mohammed\Downloads\core\pywikibot\page\__init__.py", line 5384, in site
    self.parse()
  File "C:\Users\Mohammed\Downloads\core\pywikibot\page\__init__.py", line 5339, in parse
    raise InvalidTitleError('{!r} contains illegal char(s) {!r}'
pywikibot.exceptions.InvalidTitleError: '{{PAGENAME}}' contains illegal char(s) '{'
CRITICAL: Exiting due to uncaught exception <class 'pywikibot.exceptions.InvalidTitleError'>

version.py:

Pywikibot: [https] r-pywikibot-core (aa581da, g14835, 2021/05/13, 20:40:59, master)
Release version: 6.2.0.dev0
requests version: 2.25.1
    certificate test: ok
Python: 3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)]

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

[pywikibot/core@master] [bugfix] Ignore InvalidTitleError in commonscat.py

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

Change 692699 merged by jenkins-bot:

[pywikibot/core@master] [bugfix] Ignore InvalidTitleError in commonscat.py

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