Re: Handling pypgsql DB API 2.0 exceptions

gerhard quell <gquell-N1YKUU++/[email protected]> Tue, 21 Oct 2003 16:02:56 +0200
Newsgroups gmane.comp.python.db.pypgsql.user
Message-ID <[email protected]>
Hi Terry,

  try this:

  try:
   do query
  except PgSQL.OperationalError, msg:
   ...

Cheers,

  Gerhard
--------------
Terry MacDonald wrote:
> 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
> _______________________________________________
> Pypgsql-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/pypgsql-users
> 


-- 
------------------------------------------------------ skequell ------
  Gerhard Quell                       Software & Knowledge Engineering
  Schützenweg 3      eMail:     gquell-N1YKUU++/[email protected]  Fon: 0731-26400651
  89275 Elchingen    web  : http://www.skequell.de  Fax: 0731-26400652
---Aus Sicherheitsgründen: bitte keine Word-, Excel-Dateianhänge -----



-------------------------------------------------------
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