Thread: https://wiki.postgresql.org/wiki/Psycopg2_Tutorial

https://wiki.postgresql.org/wiki/Psycopg2_Tutorial

From
Rick Widmer
Date:
May I suggest a subtle change to error handling examples on this page...


For example...

except:    print "I am unable to connect to the database"

Should be:

except psycopg2.Error as e:    print "I am unable to connect to the database: %s" % e



Postgress/psycopg2 return very good information in the exception that 
deserves to be displayed.  The print needs to display a %s formatted 
value of the exception because the exception contains structured data 
that does not display well.


except Exception as e:


would work as well, but the exception above should only trigger on 
database errors.

IMHO the error messages are worth knowing about, and should be part of 
the example.

Thanks, Rick