goldsmith / Wikipedia

A Pythonic wrapper for the Wikipedia API
https://wikipedia.readthedocs.org/
MIT License
2.88k stars 519 forks source link

wikipedia.page('Spectrochemistry').links raises KeyError exception #290

Open rneilsen opened 3 years ago

rneilsen commented 3 years ago

Trying to access the "Spectrochemistry" page's 'links' object reliably raises a KeyError, as demonstrated below.

Having a look at the page (permalink here to current revision as it is right now), I think it actually doesn't contain any internal wikipedia links - all of its links appear to be to external webpages (no idea what's going on with that). So I think if the API finds a page without any links it chokes when asked for the links, but presumably a more graceful behaviour would be to simply return an empty list instead.


Python 3.9.6 (default, Aug 19 2021, 16:32:39)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import wikipedia
>>> wikipedia.__version__
(1, 4, 0)
>>> wp = wikipedia.page('Spectrochemistry')
>>> wp.title
'Spectrochemistry'
>>> wp.pageid
'14657447'
>>> wp.links
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/rich/.pyenv/versions/3.9.6/lib/python3.9/site-packages/wikipedia/wikipedia.py", line 607, in links
    self._links = [
  File "/home/rich/.pyenv/versions/3.9.6/lib/python3.9/site-packages/wikipedia/wikipedia.py", line 607, in <listcomp>
    self._links = [
  File "/home/rich/.pyenv/versions/3.9.6/lib/python3.9/site-packages/wikipedia/wikipedia.py", line 423, in __continued_query
    for datum in pages[self.pageid][prop]:
KeyError: 'links'
>>>```