why is the wikipedia api not working for me ?
I wanted to try to use the Wikipedia api and was wondering if someone could help me decipher my error.
This is what I did. not really certain as to why this is causing me an error. it
ty seemed pretty straightforward for me :(
pip install Wikipedia
import warnings
warnings.filterwarnings("ignore")
import wikipedia
import random
value=input("Enter the words: ")
try:
m=wikipedia.search(value,3)
print(wikipedia.summary(m[0],sentences=2))
# print(p)
except wikipedia.exceptions.DisambiguationError as e:
s=random.choice(e.options)
p=wikipedia.summary(s,sentences=2)
print(p)
and the error that im getting is this:
DisambiguationError Traceback (most recent call last)
<ipython-input-1-9e328532aa15> in <module>
10 m=wikipedia.search(value,3)
---> 11 print(wikipedia.summary(m[0],sentences=2))
12 # print(p)
~\Anaconda3\lib\site-packages\wikipedia\util.py in __call__(self, *args, **kwargs)
27 else:
---> 28 ret = self._cache[key] = self.fn(*args, **kwargs)
29
~\Anaconda3\lib\site-packages\wikipedia\wikipedia.py in summary(title, sentences, chars, auto_suggest, redirect)
230 # also, use page's error checking to raise DisambiguationError if necessary
--> 231 page_info = page(title, auto_suggest=auto_suggest, redirect=redirect)
232 title = page_info.title
~\Anaconda3\lib\site-packages\wikipedia\wikipedia.py in page(title, pageid, auto_suggest, redirect, preload)
275 raise PageError(title)
--> 276 return WikipediaPage(title, redirect=redirect, preload=preload)
277 elif pageid is not None:
~\Anaconda3\lib\site-packages\wikipedia\wikipedia.py in __init__(self, title, pageid, redirect, preload, original_title)
298
--> 299 self.__load(redirect=redirect, preload=preload)
300
~\Anaconda3\lib\site-packages\wikipedia\wikipedia.py in __load(self, redirect, preload)
392
--> 393 raise DisambiguationError(getattr(self, 'title', page['title']), may_refer_to)
394
DisambiguationError: "rest" may refer to:
Kneeling
Lying (position)
Sitting
Squatting position
Support (structure)
Rest (cue sports)
Arm rest
Head rest
Footrest
Representational state transfer
Restricted Environmental Stimulation Technique
reStructuredText
REST (gene)
Rest (music)
Rest (band)
Rest (Gregor Samsa album)
Rest (Charlotte Gainsbourg album)
39/Smooth
Glory
Saints and Sinners
Home Again
Invincible
Conditions
Dear Lord and Father of Mankind
Relief Society of Tigray
Rest (finance)
Bank reserves
Retail Employees Superannuation Trust
Leisure
Relaxation technique
Sleep
Rest (physics)
Rest, Kansas
Revised Extended Standard Theory
Royal Engineers
Bed rest
All pages with titles beginning with Rest
All pages with titles containing Rest
During handling of the above exception, another exception occurred:
DisambiguationError Traceback (most recent call last)
<ipython-input-1-9e328532aa15> in <module>
13 except wikipedia.exceptions.DisambiguationError as e:
14 s=random.choice(e.options)
---> 15 p=wikipedia.summary(s,sentences=2)
16 print(p)
~\Anaconda3\lib\site-packages\wikipedia\util.py in __call__(self, *args, **kwargs)
26 ret = self._cache[key]
27 else:
---> 28 ret = self._cache[key] = self.fn(*args, **kwargs)
29
30 return ret
~\Anaconda3\lib\site-packages\wikipedia\wikipedia.py in summary(title, sentences, chars, auto_suggest, redirect)
229 # use auto_suggest and redirect to get the correct article
230 # also, use page's error checking to raise DisambiguationError if necessary
--> 231 page_info = page(title, auto_suggest=auto_suggest, redirect=redirect)
232 title = page_info.title
233 pageid = page_info.pageid
~\Anaconda3\lib\site-packages\wikipedia\wikipedia.py in page(title, pageid, auto_suggest, redirect, preload)
274 # if there is no suggestion or search results, the page doesn't exist
275 raise PageError(title)
--> 276 return WikipediaPage(title, redirect=redirect, preload=preload)
277 elif pageid is not None:
278 return WikipediaPage(pageid=pageid, preload=preload)
~\Anaconda3\lib\site-packages\wikipedia\wikipedia.py in __init__(self, title, pageid, redirect, preload, original_title)
297 raise ValueError("Either a title or a pageid must be specified")
298
--> 299 self.__load(redirect=redirect, preload=preload)
300
301 if preload:
~\Anaconda3\lib\site-packages\wikipedia\wikipedia.py in __load(self, redirect, preload)
391 may_refer_to = [li.a.get_text() for li in filtered_lis if li.a]
392
--> 393 raise DisambiguationError(getattr(self, 'title', page['title']), may_refer_to)
394
395 else:
DisambiguationError: "Glory" may refer to:
Glory (honor)
Kleos
Glory (Buffy the Vampire Slayer)
Glory (comics)
mainline My Little Pony unicorn pony
Glory (1956 film)
Glory (1989 film)
Glory (2016 film)
Glory (Britney Spears album)
Glory (Kutless album)
Glory (Manafest album)
Glory (Michael W. Smith album)
Glory (EP)
The Glory Album
Tomas Barfod
Olamide
"Glory" (Bastille song)
"Glory" (Common and John Legend song)
"Glory" (Jay-Z song)
"Glory" (KMFDM song)
Glory Song
Lift
Conqueror
Without Fear
Trippy Notes for Bass
American Tragedy
R.O.S.E.
LoveJo
Free Weezy Album
Adventure
Mirror Master
Graduation
Glory (novel)
The Glory
Glory (sculpture)
work by Banksy
Europa
Richard Berg
Glory (singer)
Glory (wrestler)
Glory Leppänen
Glory, Georgia
Glory, Minnesota
Glory, Texas
Glory (religion)
Glory (religious iconography)
Glorification
Glory Be to the Father
Glory (optical phenomenon)
Glory (satellite)
Ulmus parvifolia 'Glory'
Glory (1802 ship)
Glory-class container ship
Carnival Glory
French ship Gloire
HMS Glory
London & Overseas Freighters
Glory (kickboxing)
Ohio Glory
Perth Glory FC
All pages with titles beginning with Glory
All pages with titles containing Glory
Gloria (disambiguation)
Glory, Glory (disambiguation)
Glory hole (disambiguation)
Posted Jun 1, 2021, 12:04 PM UTC