Page MenuHomePhabricator

UnicodeDecodeError in logger class
Closed, ResolvedPublic

Description

After this commit I have an issue with running pywikibot.data.api.Request() function containing unicode strings with non-ascii characters if 'site' property is not explicitly defined.

Say, this code

# -*- coding: utf-8 -*-
import pywikibot

site = pywikibot.getSite('ru', 'wikipedia')

r = pywikibot.data.api.Request(action='purge', titles=u'Россия')

returns

Traceback (most recent call last):
  File "test.py", line 6, in <module>
    r = pywikibot.data.api.Request(action='purge', titles=u'Россия')
  File "/shared/pywikipedia/core/pywikibot/data/api.py", line 1108, in __init__
    warn('Request() invoked without a site', RuntimeWarning, 2)
  File "/usr/lib/python2.7/logging/__init__.py", line 1713, in _showwarning
    logger.warning("%s", s)
  File "/usr/lib/python2.7/logging/__init__.py", line 1164, in warning
    self._log(WARNING, msg, args, **kwargs)
  File "/usr/lib/python2.7/logging/__init__.py", line 1271, in _log
    self.handle(record)
  File "/usr/lib/python2.7/logging/__init__.py", line 1281, in handle
    self.callHandlers(record)
  File "/usr/lib/python2.7/logging/__init__.py", line 1321, in callHandlers
    hdlr.handle(record)
  File "/usr/lib/python2.7/logging/__init__.py", line 749, in handle
    self.emit(record)
  File "/shared/pywikipedia/core/pywikibot/userinterfaces/terminal_interface_base.py", line 494, in emit
    ('warn(', 'exceptions.', 'Warning)', 'Warning,'))
  File "/shared/pywikipedia/core/pywikibot/userinterfaces/terminal_interface_base.py", line 493, in <genexpr>
    s in msg for s in
UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 118: ordinal not in range(128)
<type 'exceptions.UnicodeDecodeError'>

Event Timeline

korzhimanov raised the priority of this task from to Needs Triage.
korzhimanov updated the task description. (Show Details)
korzhimanov added a project: Pywikibot-compat.
korzhimanov added a subscriber: korzhimanov.
Restricted Application added subscribers: Aklapper, Unknown Object (MLST). · View Herald TranscriptMay 13 2015, 11:37 AM
XZise added a subscriber: XZise.

Hmm seems that the message is bytes in Python 2.

XZise set Security to None.

Change 210681 had a related patch set uploaded (by XZise):
[FIX] TerminalHandler: Expect str in Python 2

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

Change 210681 merged by jenkins-bot:
[FIX] TerminalHandler: Expect str in Python 2

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