Wikipedia
Wikipedia copied to clipboard
Fix title retrieval in page function.
Problem
-
wikipedia.summary()raises error on common wordsif auto_suggest is set to True(which is by default). - Also see #284, #279, #266 for more details.
- In simple words if you use
wikipedia.summary("loki")then it will raisewikipedia.exceptions.DisambiguationError:"lok"may refer to: . Which suggests that it is searching forlokinstead ofloki.
Cause of Problem
- When calling the
summaryfunction, it calls thepagefunction. where is auto_suggest is true then we try to check for the valid title throughsearchfunction which return theresults and suggestion. - But while assigning the title variable
title = suggestion or results[0]like this we are applying thesuggestion firstand if suggestion not found then result. Which causes this problem. - Actually
title = results[0] or suggestionshould be used which means set title toresults[0] firstand if results[0] is not available then set it to suggestion.
Changes
- At file wikipedia/wikipedia.py line 272
- suggestion or results[0]
+ results[0] or suggestion
Fixes
- #284
- #279
- #266
If results[0] is not available this will throw an IndexError, not set title to suggestion.