Wikipedia page id in wikipedia.page error does not match search query
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'>
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 @nielstron Maybe you want to check this issue.
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().
Yeah I find that I need to set
auto_suggest=Falsewhen I know the page names I have exist, i.e. I've gotten the names fromwikipedia.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.
Likewise! Thanks.
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!
wikipedia.summary(Query, sentences=2, auto_suggest=False, redirect=True), It's working!
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