Page MenuHomePhabricator

can't load page whose title has a certain character
Closed, InvalidPublic

Description

Error:

$ ./test_page.py
family and mylang are not set.
Defaulting to family='test' and mylang='test'.
Traceback (most recent call last):
  File "./test_page.py", line 7, in <module>
    page = pywikibot.Page(site, "Beyoncé Knowles")
  File "/home/dan/work/pywikibot/core/pywikibot/tools/__init__.py", line 1476, in wrapper
    return obj(*__args, **__kw)
  File "/home/dan/work/pywikibot/core/pywikibot/page.py", line 2242, in __init__
    super(Page, self).__init__(source, title, ns)
  File "/home/dan/work/pywikibot/core/pywikibot/page.py", line 199, in __init__
    self._link = Link(title, source=source, defaultNamespace=ns)
  File "/home/dan/work/pywikibot/core/pywikibot/page.py", line 5439, in __init__
    if u"|" in self._text:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 6: ordinal not in range(128)
<type 'exceptions.UnicodeDecodeError'>
CRITICAL: Closing network session.

Test code:

#!/usr/bin/env python
# *-* encoding: utf-8

import pywikibot

site = pywikibot.Site('en', 'wikipedia')
page = pywikibot.Page(site, "Beyoncé Knowles")

Event Timeline

When I install pywikibot it gives the version: pywikibot-3.0.20180304.tar.gz

I guess you are using python 2?

Then either add the following line at top of the file:

from __future__ import unicode_literals

or use "u" prefix when instantiating the page:

page = pywikibot.Page(site, u"Beyoncé Knowles")

DanFr claimed this task.

I am using python2, and the "u" worked! Genius!

My own more complicated actual code fails with the "from future ..", but I'll work on it.

Thanks!

Xqt changed the task status from Resolved to Invalid.Apr 2 2018, 2:24 PM