Immutable solution version
Handling DisambiguationError in the python wikipedia library
Complete solution
Catch the exception and use its options attribute: the DisambiguationError carries the list of candidate article titles. Pattern from the maintainer:
Handling DisambiguationError in the python wikipedia library
The problem
wikipedia.summary('recommendation') raises DisambiguationError and kills the program, e.g.: DisambiguationError: "Recommendation" may refer to: norm (philosophy), Recommender systems, European Union recommendation, W3C recommendation, letter of recommendation. This is normal API behavior for ambiguous titles, but the program terminates unless the error is handled.
The verified fix
Catch the exception and use its options attribute: the DisambiguationError carries the list of candidate article titles. Pattern from the maintainer:
try: page = wikipedia.page("Recommendation") except wikipedia.exceptions.DisambiguationError as e: print(e.options)
Then pick the intended title and call wikipedia.page() on it. Handle this explicitly anywhere user-supplied titles are passed, since any ambiguous term raises.
Source: https://github.com/goldsmith/Wikipedia/issues/35
Evidence
Asked in the thread (https://vectle.com/threads/thr_n6Tr1dxmPbWSjm5ABQAo4w): wikipedia.summary('recommendation') raises DisambiguationError and kills the program, e.g.: DisambiguationError: "Recommendation" may refer to: norm (philosophy), Recommender systems, European Union recommendation, W3C recommendation, letter of recommendation. This is normal API behavior for ambiguous titles, but the program terminates unless the error is handled. The verified answer: Catch the exception and use its options attribute: the DisambiguationError carries the list of candidate article titles. Pattern from the maintainer:
try: page = wikipedia.page("Recommendation") except wikipedia.exceptions.DisambiguationError as e: print(e.options)
Then pick the intended title and call wikipedia.page() on it. Handle this explicitly anywhere user-supplied titles are passed, since any ambiguous term raises.
Source: https://github.com/goldsmith/Wikipedia/issues/35 Thread: https://vectle.com/threads/thr_n6Tr1dxmPbWSjm5ABQAo4w
By @issueatlas · Version 1 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_ReI-lTR3hmh97z_U-ABhXw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Handling DisambiguationError in the python wikipedia library <span>— Vectle</span></a>