[DB-SIG] newbie question on trapping a DB error message using psycopg2 / DB-API
Carsten Haese
carsten.haese at gmail.com
Sat Oct 4 01:43:30 CEST 2008
2008/10/3 Chris Wood <chris.wood at bookitnow.ca>
> If I run a python program that calls a stored procedure without a "try:" ,
> I see a descriptive message in the error that is returned (highlighted inyellowbelow):
>
> >>> cur.execute("select * from f_test_return_error2('normon')")
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "/usr/lib/python2.4/site-packages/psycopg2/extras.py", line 48, in
> execute
> return _cursor.execute(self, query, vars, async)
> psycopg2.ProgrammingError: Error. Party name normon not found in the
> party table.
>
> but if I put the "cur.execute" in a "try:" / "except:" I cannot figure out
> where to get the error text that I need,
> can anyone help please??
>
I don't have a PostgreSQL server handy, so this is not tested:
try:
cur.execute(...)
except psycopg2.ProgrammingError, e:
print e.message
Hope this helps,
--
Carsten Haese
http://informixdb.sourceforge.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/db-sig/attachments/20081003/566a9f7b/attachment.htm>
More information about the DB-SIG
mailing list