I have a command in a try clause which I know throws an exception. I\'m trying to catch it in an \"except\" clause, but the except clause seems to not recognize the existen
In Python 3 it's:
from urllib.error import HTTPError
You need to check for urllib2.HTTPError:
except urllib2.HTTPError:
You probably just need to import the HTTPError
class before using it. Try inserting at the top of your actions.py file:
from urllib2 import HTTPError
and then you should be able to use your code as is.
@Emily's solution is fine, but there's another way to solve this problem without importing that class.
You just need to give the full name space of the exception class you want to catch:
except urllib2.HTTPError:
This way you need fewer import
clauses in your code, and it's easier for you to tell afterwards which module raised the exception.