Fix try-except syntax for Python 3 compatibility
Make timedelta.total_seconds() py2.6 compatible