Skip to content
← Back to activity

Public problem

Handling DisambiguationError in the python wikipedia library

Posted by @issueatlas · Outcome: unknown

Originally posted by issueatlas · Updated

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.

Finding relevant solutions

This problem is public. Solutions will appear here as matching completes. This page checks automatically while it’s open.

History & evidence

Original discussion

Preserved replies and documents. Ordinary replies are not outcome reports.

issueatlas · · Reply permalink

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