Wikipedia icon indicating copy to clipboard operation
Wikipedia copied to clipboard

Wikipedia page id in wikipedia.page error does not match search query

Open nielstron opened this issue 7 years ago • 9 comments

Trying to access a valid wikipedia page (with redirect, see https://en.wikipedia.org/wiki/Petawatt) this error is thrown:

>>> wikipedia.page("Petawatt")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/.local/share/virtualenvs/quantulum3-mx2jnqkR/lib/python3.6/site-packages/wikipedia/wikipedia.py", line 276, in page
    return WikipediaPage(title, redirect=redirect, preload=preload)
  File "/home/user/.local/share/virtualenvs/quantulum3-mx2jnqkR/lib/python3.6/site-packages/wikipedia/wikipedia.py", line 299, in __init__
    self.__load(redirect=redirect, preload=preload)
  File "/home/user/.local/share/virtualenvs/quantulum3-mx2jnqkR/lib/python3.6/site-packages/wikipedia/wikipedia.py", line 345, in __load
    raise PageError(self.title)
wikipedia.exceptions.PageError: Page id "per watt" does not match any pages. Try another id!

The PageError contains a wrong id following this legitimate search query. This does not occur if auto_suggest is turned off. Anyway the title shouldn't be changed in the pageerror on my opinion.

>>> wikipedia.page("Petawatt", auto_suggest=False)
<WikipediaPage 'Watt'>

nielstron avatar Oct 10 '18 21:10 nielstron

I have the same issue.

>>> import wikipedia

>>> wikipedia.page("Republican Party (United States)")

Error: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\fredr\Anaconda3\lib\site-packages\wikipedia\wikipedia.py", line 276, in page return WikipediaPage(title, redirect=redirect, preload=preload) File "C:\Users\fredr\Anaconda3\lib\site-packages\wikipedia\wikipedia.py", line 299, in __init__ self.__load(redirect=redirect, preload=preload) File "C:\Users\fredr\Anaconda3\lib\site-packages\wikipedia\wikipedia.py", line 345, in __load raise PageError(self.title) wikipedia.exceptions.PageError: Page id "republican party untied states" does not match any pages. Try another id!

Thank you for mentioning auto_suggest @nielstron , that will solve my problem.

Edit: Is this not a bigger problem than just the error message is wrong? Because the wikipedia page I want do exist and should not have fail.

wigsnes avatar Oct 12 '18 19:10 wigsnes

@wigsnes @nielstron Maybe you want to check this issue.

nawabhussain avatar Aug 23 '19 15:08 nawabhussain

Yeah I find that I need to set auto_suggest=False when I know the page names I have exist, i.e. I've gotten the names from wikipedia.search().

kylebarron avatar Jan 29 '20 16:01 kylebarron

Yeah I find that I need to set auto_suggest=False when I know the page names I have exist, i.e. I've gotten the names from wikipedia.search().

Thank you so much! I've been tearing my hair out over this, trying to figure out why two-three articles out of several hundred with the same URL schema are throwing errors.

PersonofNote avatar Apr 14 '20 16:04 PersonofNote

Likewise! Thanks.

zacharyhorvitz avatar Aug 07 '20 02:08 zacharyhorvitz

Thanks to this thread, I finally found the solution I needed:

Use wikipedia.search (NOT wikipedia.suggest, which I was using, but which seems to be completely useless for my needs) and lookup the first value in the array ([0] - the first search result) to find a valid article. Then, use definition=wikipedia.summary(word, sentences = num_sentences, auto_suggest=False, redirect=True).

This solved the problem for me, and I hope it does for everyone else!

samfriedmann avatar Oct 03 '20 04:10 samfriedmann

wikipedia.summary(Query, sentences=2, auto_suggest=False, redirect=True), It's working!

triposat avatar May 19 '21 14:05 triposat

When i search for thomas edison it gives me an error: raise PageError(self.title) wikipedia.exceptions.PageError: Page id "thomas ed8son" does not match any pages. Try another id! Other searches are ok. except it prints more then 2 sentences...

import wikipedia

while True:
    input = raw_input('Question: ')  # raw input is python2 input is python3
    print wikipedia.summary(input, sentences=2)

ok i forgot to save the file before starting it.. nvm

rene8-droid avatar May 13 '22 05:05 rene8-droid