Search code examples
pythonwikipedia

Error in Python using wikipedia module: wikipedia.exceptions.PageError: Page id "harry plotter" does not match any pages. Try another id


newbie in Python here

when I run this simple code (to load Harry Potter page and simply print it) it returns me Error with the wrong name I wanted to search (harry plotter) can anyone tell me how to fix? thank you!

import wikipedia

page = wikipedia.page("Harry Potter")

print(page.summary)

Error message:

Traceback (most recent call last):
File "C:\Users\Lidor\PycharmProjects\pythonProject\search_engine.py", line 7, in <module>
  page = wikipedia.page(search[0])
File "C:\Users\Lidor\PycharmProjects\pythonProject\venv\lib\site- 
  packages\wikipedia\wikipedia.py", line 276, in page
  return WikipediaPage(title, redirect=redirect, preload=preload)
File "C:\Users\Lidor\PycharmProjects\pythonProject\venv\lib\site- 
  packages\wikipedia\wikipedia.py", line 299, in __init__
  self.__load(redirect=redirect, preload=preload)
File "C:\Users\Lidor\PycharmProjects\pythonProject\venv\lib\site- 
  packages\wikipedia\wikipedia.py", line 345, in __load
  raise PageError(self.title)
  wikipedia.exceptions.PageError: Page id "harry plotter" does not match any pages. Try 
    another id!

Solution

  • This appears to be a strange result of auto_suggest being set by default. If you do

    wikipedia.page("Harry Potter", auto_suggest=False)
    

    It works fine. Otherwise it autocompletes potter to plotter, hence the error.