Handling pypgsql DB API 2.0 exceptions
Terry MacDonald <terry-TU+o4ct7AZYNcFTW2g63AdBc4/[email protected]> 21 Oct 2003 14:14:16 +0100
| Newsgroups | gmane.comp.python.db.pypgsql.user |
|---|---|
| Message-ID | <1066742056.1176.6.camel@bigmac> |
Hi,
I am fairly new to using python and pypgsql and what I may ask here may
be solved by the obvious, so my apologies if this sounds dumb, but I
have looked around all the (sparse) documentation and found nothing that
helps. Anyway how do I get my program, that imports pgSQL, to recognise
the DB API exception values, e.g. OperationalError, for when I place
them in a try...except block ala...
try:
do query
except OperationalError:
....
...I get the following error:
=========================================================================
Traceback (most recent call last):
File "/usr/lib/python2.2/site-packages/mod_python/apache.py", line
335, in HandlerDispatch
result = object(req)
File "/usr/lib/python2.2/site-packages/mod_python/publisher.py", line
194, in handler
result = apply(object, (), args)
File "/var/www/html/python/cricket.py", line 60, in registerLeague
except OperationalError:
NameError: global name 'OperationalError' is not defined
==========================================================================
I would have thought the imported module, in this case pgSQL, would have
defined them and made them available to calling modules, but obviously
this is not the case.
Any help much appreciated and I am sure the solution will educate me
more in how python works and how to use it.
Cheers,
Terry
-------------------------------------------------------
This SF.net email is sponsored by OSDN developer relations
Here's your chance to show off your extensive product knowledge
We want to know what you know. Tell us and you have a chance to win $100
http://www.zoomerang.com/survey.zgi?HRPT1X3RYQNC5V4MLNSV3E54