Postgresql Exception Handling In Python