https://wiki.postgresql.org/wiki/Psycopg2_Tutorial - Mailing list pgsql-www

From Rick Widmer
Subject https://wiki.postgresql.org/wiki/Psycopg2_Tutorial
Date
Msg-id e10fad27-acfe-7319-90ef-ad92da3a1ea2@rickwidmer.com
Whole thread Raw
List pgsql-www
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








pgsql-www by date:

Previous
From: "Rader, David"
Date:
Subject: Re: patch - BigSQL packages on Download
Next
From: "Joshua D. Drake"
Date:
Subject: Re: patch - BigSQL packages on Download