Page MenuHomePhabricator

Deprecation warning fails with UnicodeDecoreError
Closed, DeclinedPublic

Description

C:\pwb\SVN\core>pwb.py checkvotes -admin -v
Pywikibot SVN repository
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)]
Found 1 wikipedia:de processes running, including this one.
Retrieving 3 pages from wikipedia:de.
Working on u'Wikipedia:Adminkandidaturen/Altkatholik62 2016'


>>> Wikipedia:Adminkandidaturen/Altkatholik62 2016 <<<

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

ERROR: UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 50:
ordinal not in range(128)
Traceback (most recent call last):
  File "C:\pwb\SVN\core\pwb.py", line 258, in <module>
    if not main():
  File "C:\pwb\SVN\core\pwb.py", line 254, in main
    run_python_file(filename, [filename] + args, argvu, file_package)
  File "C:\pwb\SVN\core\pwb.py", line 121, in run_python_file
    main_mod.__dict__)
  File ".\scripts\xqbot\checkvotes.py", line 623, in <module>
    main()
  File ".\scripts\xqbot\checkvotes.py", line 618, in main
    bot.run()
  File "C:\pwb\SVN\core\pywikibot\bot.py", line 1409, in run
    self.treat(page)
  File "C:\pwb\SVN\core\pywikibot\bot.py", line 1696, in treat
    super(ExistingPageBot, self).treat(page)
  File "C:\pwb\SVN\core\pywikibot\bot.py", line 1760, in treat
    super(NoRedirectPageBot, self).treat(page)
  File "C:\pwb\SVN\core\pywikibot\bot.py", line 1623, in treat
    self.treat_page()
  File ".\scripts\xqbot\checkvotes.py", line 225, in treat_page
    text = self.load(page)
  File ".\scripts\xqbot\checkvotes.py", line 531, in load
    restrictions = page.getRestrictions()  # TODO: f├╝r Pr├╝fung hier ausschlie├
ƒen
  File "C:\pwb\SVN\core\pywikibot\tools\__init__.py", line 1292, in wrapper
    issue_deprecation_warning(name, instead, depth)
  File "C:\pwb\SVN\core\pywikibot\tools\__init__.py", line 1258, in issue_deprec
ation_warning
    warning_class, depth + 1)
  File "C:\Python27\lib\logging\__init__.py", line 1717, in _showwarning
    s = warnings.formatwarning(message, category, filename, lineno, line)
  File "C:\Python27\lib\warnings.py", line 46, in formatwarning
    s += "  %s\n" % line
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 50: ordinal
 not in range(128)
Dropped throttle(s).
<type 'exceptions.UnicodeDecodeError'>
CRITICAL: Closing network session.
Network session closed.

C:\pwb\SVN\core>

Seems the warning is for

@deprecated('Page.protection()')
def getRestrictions(self):
C:\pwb\SVN\core>pwb.py version
Pywikibot: pywikibot-core (4753f89, s8504, 2016/05/03, 03:45:30, ok)
Release version: 3.0-dev
requests version: 2.7.0
  cacerts: C:\Python27\lib\site-packages\requests\cacert.pem
    certificate test: ok
Python: 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)]
PYWIKIBOT2_DIR: Not set
PYWIKIBOT2_DIR_PWB: C:\pwb\SVN\core
PYWIKIBOT2_NO_USER_CONFIG: Not set
Config base dir: C:\pwb\SVN\core
Usernames for family "wikipedia":
        gv: Xqbot (no sysop configured)
Usernames for family "commons":
        commons: Xqbot (no sysop configured)
Usernames for family "wikidata":
        repo: Xqt (no sysop configured)

C:\pwb\SVN\core>

Event Timeline

Xqt triaged this task as High priority.May 3 2016, 1:13 PM

This occurs because the depth parameter of issue_deprecation_warning is 2 i.e. it does not fail for other values but I've no clue what this means.

I suspect if you remove the # TODO: für Prüfung hier ausschließen it will work.

I see: It is the comment which breaks that warning message. The script line is:

restrictions = page.getRestrictions()  # TODO: für Prüfung hier ausschließen
Xqt lowered the priority of this task from High to Low.May 3 2016, 1:55 PM

I assume checkvotes.py has a coding line

# -*- coding: utf-8 -*-

(otherwise the file wouldn't compile.. I believe)

Then it feels like a bug in warnings.py in Python 2.x , but I am only about 95% sure, and if it is it is unlikely to have been fixed yet in 2.7.10+.

We can work around it by catching the exception in issue_deprecation_warning and disabling including the source line in the output or reducing the depth to 1.

Xqt lowered the priority of this task from Low to Lowest.Mar 10 2020, 10:52 AM

Declined in favour of Python 3. Python 2 will be dropped at the end of this month.