question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

failure to raise DisambiguationError for "Leaching" page on Wikipedia

See original GitHub issue

Using pymediawiki 0.3.15 with Python 3.6.3 on Linux, I observed the following error when attempting to access the disambiguation page for “Leaching” on Wikipedia.

python -c "import mediawiki; wikipedia=mediawiki.MediaWiki(); wikipedia.page('Leaching')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/lebedov/miniconda3/lib/python3.6/site-packages/mediawiki/mediawiki.py", line 731, in page
    preload=preload)
  File "/home/lebedov/miniconda3/lib/python3.6/site-packages/mediawiki/mediawikipage.py", line 72, in __init__
    self.__load(redirect=redirect, preload=preload)
  File "/home/lebedov/miniconda3/lib/python3.6/site-packages/mediawiki/mediawikipage.py", line 532, in __load
    self._raise_disambiguation_error(page, pageid)
  File "/home/lebedov/miniconda3/lib/python3.6/site-packages/mediawiki/mediawikipage.py", line 569, in _raise_disambiguation_error
    one_disambiguation['title'] = item[0]['title']
  File "/home/lebedov/miniconda3/lib/python3.6/site-packages/bs4/element.py", line 1011, in __getitem__
    return self.attrs[key]
KeyError: 'title'

Relatedly, wikipedia 1.4.0 correctly raises a DisambiguationError exception for the above.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
barrustcommented, Feb 1, 2019

Great catch, I hadn’t looked at the title portion in awhile. Would you like to open a new issue so that we can track this? Thanks!

0reactions
awbirdsallcommented, Feb 1, 2019

@barrust : here’s an example for “Lincoln Museum” (https://en.wikipedia.org/wiki/Lincoln_Museum):

from mediawiki import MediaWiki, DisambiguationError
wikipedia = MediaWiki()

try:
    p = wikipedia.page("Lincoln Museum")
except DisambiguationError as d:
    print(d.details[5]['title'])
    print(d.details[5]['description'])

I’d expect the title here to be only “Ford’s Theatre” since that’s the title of the link, but instead the title is the same as the full description (both are Ford's Theatre, Washington, DC, USA — where Abraham Lincoln was assassinated; known as Lincoln Museum from 1936 to 1965 and legally "Ford's Theater (Lincoln Museum)" since 1965).

In [8]: print(mediawiki.__version__)                                                                               
0.6.0
Read more comments on GitHub >

github_iconTop Results From Across the Web

Wikipedia disambiguation error - python - Stack Overflow
You could catch the DisambiguationError and chose one of these pages randomly. try: p = wikipedia.page(string) except wikipedia.DisambiguationError as e: s ...
Read more >
Quickstart — wikipedia 0.9 documentation
summary will raise a DisambiguationError if the page is a disambiguation page, or a PageError if the page doesn't exist (although by default,...
Read more >
why is the wikipedia api not working for me ? : r/learnpython
I wanted to try to use the Wikipedia api and was wondering if ... use page's error checking to raise DisambiguationError if necessary....
Read more >
Wikipedia:Disambiguation
Disambiguation in Wikipedia is the process of resolving conflicts that arise when a potential article title is ambiguous, most often because it refers...
Read more >
Getting Started with Python's Wikipedia API - Stack Abuse
In this article, we will be using the Wikipedia API to retrieve data ... wikipedia.summary will raise a "disambiguation error" if the page...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found