Update task.py

Change exception to be Python 3 compatible