Page MenuHomePhabricator

UnicodeEncodeError in Page.__repr__()
Closed, ResolvedPublic

Description

Error occurred in sd-wiki:

>>> Fixing redirects on wikipedia:sd <<<
Retrieving special page...
Retrieving 4 pages from wikipedia:sd.


>>> ???? ???:Gangleri <<<
ERROR: Page [[sd:???? ???:Gangleri]] is a circular redirect.
Skipping [[sd:???? ???:Gangleri]].


>>> ????????? ?????? ??? ??????? ??? ????? ? ???? ?????? ??? ????? ?? ????? <<<
   Links to: [[????????? ?????? ??? ??????????? ???? ????? ? ???? ?????? ??? ???
?? ?? ??????]].
   Links to: [[????????? ?????? ??? ??????????? ???? ????? ? ?????????? ?? ?????
 ?? ??????]].
@@ -1 +1 @@
- #REDIRECT[[????????? ?????? ??? ??????????? ???? ????? ? ???? ?????? ??? ?????
 ?? ??????]]
+ #????? [[????????? ?????? ??? ??????????? ???? ????? ? ?????????? ?? ????? ??
??????]]

Traceback (most recent call last):
  File "C:\pwb\core\pwb.py", line 226, in <module>
    if not main():
  File "C:\pwb\core\pwb.py", line 220, in main
    run_python_file(filename, [filename] + args, argvu, file_package)
  File "C:\pwb\core\pwb.py", line 87, in run_python_file
    main_mod.__dict__)
  File ".\scripts\redirect.py", line 885, in <module>
    main()
  File ".\scripts\redirect.py", line 872, in main
    bot.run()
  File ".\scripts\redirect.py", line 738, in run
    self.fix_double_redirects()
  File ".\scripts\redirect.py", line 566, in fix_double_redirects
    self.fix_1_double_redirect(redir_name)
  File ".\scripts\redirect.py", line 696, in fix_1_double_redirect
    redir.save(summary)
  File "C:\pwb\core\pywikibot\tools\__init__.py", line 1229, in wrapper
    return obj(*__args, **__kw)
  File "C:\pwb\core\pywikibot\page.py", line 1080, in save
    cc=apply_cosmetic_changes, **kwargs)
  File "C:\pwb\core\pywikibot\page.py", line 1091, in _save
    watch=watch, bot=botflag, **kwargs)
  File "C:\pwb\core\pywikibot\site.py", line 1165, in callee
    return fn(self, *args, **kwargs)
  File "C:\pwb\core\pywikibot\site.py", line 4460, in editpage
    result = req.submit()
  File "C:\pwb\core\pywikibot\data\api.py", line 2094, in submit
    param_repr = str(self._params)
  File "C:\pwb\core\pywikibot\page.py", line 278, in __repr__
    title = self.title().encode(config.console_encoding)
  File "C:\Python27\lib\encodings\cp850.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode characters in position 0-8: cha
racter maps to <undefined>
<type 'exceptions.UnicodeEncodeError'>
CRITICAL: Closing network session.

Event Timeline

Xqt raised the priority of this task from to High.
Xqt updated the task description. (Show Details)
Xqt added projects: Pywikibot, Pywikibot-General.
Xqt subscribed.

This looks like the last traceback in T66958.

Yes, you are right. I breaks all my scripts on foreign wikis and I've to fallback to compat :(

Hmm I don't really understand why this is only just happening. The line in api.py was actually changed in 06925875 and that was due to Page instances now inside the parameters since b44e59ae. And the 2.0 branch does contain neither of them and shouldn't experience that problem then.

Before b44e59ae the title of the Page was usually used and in some cases it was encoded but not using the console encoding but the server encoding which is usually UTF-8 and therefore works. If it wasn't encoded it would use __repr__ but of a unicode it is save.

Change 228620 had a related patch set uploaded (by Xqt):
[FIX] Workaround fix for UnicodeEncodeError in api.py

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

Okay I mentioned T66958, but I think there are actually two different problems. This bug here shows an inability for Page.__repr__ to actually create a string, while T66958 is just about the problems that Page.__repr__ returns an unexpected type.

Change 231566 had a related patch set uploaded (by XZise):
[FIX] Page: Use repr-like if it can't be encoded

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

Change 231566 merged by jenkins-bot:
[FIX] Page: Use repr-like if it can't be encoded

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

Change 228620 abandoned by Xqt:
[FIX] Workaround fix for UnicodeEncodeError in api.py

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

XZise claimed this task.
XZise added a subscriber: Ricordisamoa.

I merged T72976 into this one as the patch fixing both bugs primarily mentions this bug.

Change 262923 had a related patch set uploaded (by XZise):
[FIX] Page: Use repr-like if it can't be encoded

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

Change 262923 merged by jenkins-bot:
[FIX] Page: Use repr-like if it can't be encoded

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