Page MenuHomePhabricator

Page.title(as_url=True) fails with umlauts in Python 2
Closed, ResolvedPublic

Description

>>> import pwb, pywikibot as py
>>> s = py.Site()
>>> p = py.Page(s, u'Brägel')
>>> p.title(as_url=True)

Traceback (most recent call last):
  File "<pyshell#25>", line 1, in <module>
    p.title(as_url=True)
  File "pywikibot\tools\__init__.py", line 1738, in wrapper
    return obj(*__args, **__kw)
  File "pywikibot\page.py", line 367, in title
    title = quote_from_bytes(encoded_title, safe='')
  File "C:\Python27\lib\urllib.py", line 1297, in quote
    if not s.rstrip(safe):
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 2: ordinal not in range(128)
>>>

whereas Python 3 works as expected

Details

Event Timeline

Xqt triaged this task as High priority.May 6 2019, 2:54 PM

Not on my PC. Is this on Windows?

$ python2 pwb.py shell
Welcome to the Pywikibot interactive shell!
>>> import pwb, pywikibot as py
>>> s = py.Site()
>>> p = py.Page(s, u'Brägel')
>>> p.title(as_url=True)
'Br%C3%A4gel'

Not on my PC. Is this on Windows?

Yes

But this needs to be fixed in page.py, instead of api.py, right? Should we fix this globally somewhere?

Change 567470 had a related patch set uploaded (by Dvorapa; owner: Dvorapa):
[pywikibot/core@master] [bugfix] Fix Python 2 Unicode error in page.py

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

Change 567470 merged by jenkins-bot:
[pywikibot/core@master] [bugfix] Fix Python 2 Unicode error in page.py

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