Handling DisambiguationError?
<p>I'm using the <code>wikipedia</code> library and I want to handle the <code>DisambiguationError</code> as an exception.  My first try was</p>

<pre><code>try:
     wikipedia.page('equipment') # could be any ambiguous term
except DisambiguationError:
     pass
</code></pre>

<p>During execution line 3 isn't reached.  A more general question is: how can I find the error type for a library-specific class like this?</p>

<p>Here's a working example:</p>

<pre><code>import wikipedia

try:
    wikipedia.page('equipment')
except wikipedia.exceptions.DisambiguationError as e:
    print("Error: {0}".format(e))
</code></pre>

<p>Regarding to your more general question <code>how can I find the error type for a library-specific class like this?</code>, my trick is actually quite simple, I tend to capture Exception and then just printing the <code>__class__</code>, that way I'll know what specific Exception I need to capture.</p>

<p>One example of figuring out which specific exception to capture here:</p>

<pre><code>try:
    0/0
except Exception as e:
    print("Exception.__class__: {0}".format(e.__class__))
</code></pre>

<p>This would print <code>Exception.__class__: &lt;type 'exceptions.ZeroDivisionError'&gt;</code>, so I knew <code>exceptions.ZeroDivisionError</code> would be the exact Exception to deal with instead of something more generic</p>

python error-handling try-except pywikipedia