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

From: Rick Widmer <rick(at)rickwidmer(dot)com>
To: pgsql-www(at)postgresql(dot)org
Subject: https://wiki.postgresql.org/wiki/Psycopg2_Tutorial
Date: 2016-05-02 21:11:08
Message-ID: e10fad27-acfe-7319-90ef-ad92da3a1ea2@rickwidmer.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Browse pgsql-www by date

  From Date Subject
Next Message Dave Page 2016-05-03 09:00:45 Re: patch - BigSQL packages on Download
Previous Message Christophe Pettus 2016-04-30 22:51:36 Re: conference slides in wiki