Page MenuHomePhabricator

fixing_redirects.py: ERROR: '� ' contains illegal char ' �' (InvalidTitleError)
Closed, ResolvedPublic

Description

Problem:

  • The script fixing_redirects.py crashes when running on any page that has the replacement character in one of the links.

Command line:

python pwb.py fixing_redirects -ignoremoves -page:"دنكن هالداين"

Error:

ERROR: '� ' contains illegal char ' �' (InvalidTitleError)

Traceback:

Traceback (most recent call last):
  File "C:\Users\Mohammed\Downloads\core\pwb.py", line 39, in <module>
    sys.exit(main())
             ^^^^^^
  File "C:\Users\Mohammed\Downloads\core\pwb.py", line 35, in main
    runpy.run_path(str(path), run_name='__main__')
  File "<frozen runpy>", line 291, in run_path
  File "<frozen runpy>", line 98, in _run_module_code
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\Mohammed\Downloads\core\pywikibot\scripts\wrapper.py", line 516, in <module>
    main()
  File "C:\Users\Mohammed\Downloads\core\pywikibot\scripts\wrapper.py", line 500, in main
    if not execute():
           ^^^^^^^^^
  File "C:\Users\Mohammed\Downloads\core\pywikibot\scripts\wrapper.py", line 487, in execute
    run_python_file(filename, script_args, module)
  File "C:\Users\Mohammed\Downloads\core\pywikibot\scripts\wrapper.py", line 147, in run_python_file
    exec(compile(source, filename, 'exec', dont_inherit=True),
  File "C:\Users\Mohammed\Downloads\core\scripts\fixing_redirects.py", line 264, in <module>
    main()
  File "C:\Users\Mohammed\Downloads\core\scripts\fixing_redirects.py", line 258, in main
    bot.run()
  File "C:\Users\Mohammed\Downloads\core\pywikibot\bot.py", line 1702, in run
    self.treat(page)
  File "C:\Users\Mohammed\Downloads\core\pywikibot\bot.py", line 1956, in treat
    self.treat_page()
  File "C:\Users\Mohammed\Downloads\core\scripts\fixing_redirects.py", line 205, in treat_page
    newtext = self.replace_links(newtext, page, target)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mohammed\Downloads\core\scripts\fixing_redirects.py", line 87, in replace_links
    is_interwikilink = mysite.isInterwikiLink(m['title'])
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mohammed\Downloads\core\pywikibot\site\_basesite.py", line 343, in isInterwikiLink
    linkfam, linkcode = pywikibot.Link(text, self).parse_site()
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mohammed\Downloads\core\pywikibot\page\_links.py", line 316, in __init__
    raise InvalidTitleError(
pywikibot.exceptions.InvalidTitleError: '�' contains illegal char '�'
CRITICAL: Exiting due to uncaught exception <class 'pywikibot.exceptions.InvalidTitleError'>

Request:

  • Please make the bot skip the page (and not crash) when encountering such pages. Thank you.

Note:

Output of version.py:

Pywikibot: [https] r-pywikibot-core (8b8c7ec, g17341, 2022/12/03, 15:38:36, master)
Release version: 8.0.0.dev0
setuptools version: 65.6.3
mwparserfromhell version: 0.6.4
wikitextparser version: n/a
requests version: 2.28.1
    certificate test: ok
Python: 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)]

Event Timeline

This comment was removed by Xqt.
Xqt changed the task status from Open to In Progress.Dec 5 2022, 2:11 PM
Xqt claimed this task.
Xqt triaged this task as Medium priority.

@Meno25: I am working on it and found a solution. Could you check the diff result, I am not able to read it:

D:\pwb\GIT\core>pwb.py fixing_redirects -ignoremoves -page:"دنكن هالداين" -simulate -lang:ar
Retrieving 1 pages from wikipedia:ar.

>>> دنكن هالداين <<<
@@ -3 +3 @@
- '''فريدريك دنكن مايكل هالداين''' {{إنج|Frederick Duncan Michael Haldane}} (و. [[1951]] – [[تقويم ميلادي|م]]) هو عالم فيزياء بريطاني ولد في يوم [[14 سبتمبر]] [[1951]] في مدينة [[لندن]] عاصمة [[المملكة المتحدة]]، درس الفيزياء في [[جامعة برنستون]] في [[الولايات المتحدة]] ونال [[جائزة نوبل في الفيزياء]] في سنة 2016 وذلك نتاج اكتشافاتهم النظرية في مجال التعدي أو الانتقال الطوري الطوبولوجي مع كل من [[ديفيد ثاوليس]] و[[مايكل كوسترليتز]].<ref>[http://wwwphy.princeton.edu/~haldane/index.html F. Duncan M. Haldane<!-- عنوان مولد بالبوت -->] {{Webarchive|url=https://web.archive.org/web/20170915221707/http://wwwphy.princeton.edu/~haldane/index.html |date=15 سبتمبر 2017}}</ref>
+ '''فريدريك دنكن مايكل هالداين''' {{إنج|Frederick Duncan Michael Haldane}} (و. [[1951]] – [[تقويم ميلادي|م]]) هو عالم فيزياء بريطاني ولد في يوم [[14 سبتمبر]] [[1951]] في مدينة [[لندن]] عاصمة [[المملكة المتحدة]]، درس الفيزياء في [[جامعة برينستون|جامعة برنستون]] في [[الولايات المتحدة]] ونال [[جائزة نوبل في الفيزياء]] في سنة 2016 وذلك نتاج اكتشافاتهم النظرية في مجال التعدي أو الانتقال الطوري الطوبولوجي مع كل من [[ديفيد ثاوليس]] و[[مايكل كوسترليتز]].<ref>[http://wwwphy.princeton.edu/~haldane/index.html F. Duncan M. Haldane<!-- عنوان مولد بالبوت -->] {{Webarchive|url=https://web.archive.org/web/20170915221707/http://wwwphy.princeton.edu/~haldane/index.html |date=15 سبتمبر 2017}}</ref>

Edit summary: بوت: إصلاح التحويلات
Do you want to accept these changes? ([y]es, [N]o, [a]ll, [q]uit):

@Meno25: I am working on it and found a solution. Could you check the diff result, I am not able to read it:

D:\pwb\GIT\core>pwb.py fixing_redirects -ignoremoves -page:"دنكن هالداين" -simulate -lang:ar
Retrieving 1 pages from wikipedia:ar.

>>> دنكن هالداين <<<
@@ -3 +3 @@
- '''فريدريك دنكن مايكل هالداين''' {{إنج|Frederick Duncan Michael Haldane}} (و. [[1951]] – [[تقويم ميلادي|م]]) هو عالم فيزياء بريطاني ولد في يوم [[14 سبتمبر]] [[1951]] في مدينة [[لندن]] عاصمة [[المملكة المتحدة]]، درس الفيزياء في [[جامعة برنستون]] في [[الولايات المتحدة]] ونال [[جائزة نوبل في الفيزياء]] في سنة 2016 وذلك نتاج اكتشافاتهم النظرية في مجال التعدي أو الانتقال الطوري الطوبولوجي مع كل من [[ديفيد ثاوليس]] و[[مايكل كوسترليتز]].<ref>[http://wwwphy.princeton.edu/~haldane/index.html F. Duncan M. Haldane<!-- عنوان مولد بالبوت -->] {{Webarchive|url=https://web.archive.org/web/20170915221707/http://wwwphy.princeton.edu/~haldane/index.html |date=15 سبتمبر 2017}}</ref>
+ '''فريدريك دنكن مايكل هالداين''' {{إنج|Frederick Duncan Michael Haldane}} (و. [[1951]] – [[تقويم ميلادي|م]]) هو عالم فيزياء بريطاني ولد في يوم [[14 سبتمبر]] [[1951]] في مدينة [[لندن]] عاصمة [[المملكة المتحدة]]، درس الفيزياء في [[جامعة برينستون|جامعة برنستون]] في [[الولايات المتحدة]] ونال [[جائزة نوبل في الفيزياء]] في سنة 2016 وذلك نتاج اكتشافاتهم النظرية في مجال التعدي أو الانتقال الطوري الطوبولوجي مع كل من [[ديفيد ثاوليس]] و[[مايكل كوسترليتز]].<ref>[http://wwwphy.princeton.edu/~haldane/index.html F. Duncan M. Haldane<!-- عنوان مولد بالبوت -->] {{Webarchive|url=https://web.archive.org/web/20170915221707/http://wwwphy.princeton.edu/~haldane/index.html |date=15 سبتمبر 2017}}</ref>

Edit summary: بوت: إصلاح التحويلات
Do you want to accept these changes? ([y]es, [N]o, [a]ll, [q]uit):

@Xqt Diff result is correct. Thank you for your work, Xqt.

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

[pywikibot/core@master] [fix] Skip invalid link titles in fixing_redirects.py

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

Change 871893 merged by jenkins-bot:

[pywikibot/core@master] [fix] Skip invalid link titles in fixing_redirects.py

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