[Zope-DB] SQL exception handling questions

Luis Mariano Luporini lluporini@yahoo.com.ar
Mon, 17 Mar 2003 18:47:29 -0300


Ok. I've created a new Zope Product following the directions in the 
README of PythonScript

The module name is GlobalModules and the directory contains a file 
called __init__.py with the following:

===== Start
# Global module assertions for Python scripts

from Products.PythonScripts.Utility import allow_module

allow_module(psycopg)
====== End

When I restart Zope I get a broken module with this explanation:

Traceback (most recent call last):
  File "//usr/share/zope//zope-2.6.1/lib/python/OFS/Application.py", line 541, in import_product
    product=__import__(pname, global_dict, global_dict, silly)
  File "//usr/share/zope//zope-2.6.1/lib/python/Products/GlobalModules/__init__.py", line 5, in ?
    allow_module(psycopg)
NameError: name 'psycopg' is not defined

What am I missing?

Thanks Dieter.
Luis.

Dieter Maurer wrote:

>Luis Mariano Luporini wrote at 2003-3-17 12:57 -0300:
> >        Now the questions:
> > 
> >        1) I've read about try/except and StandarError.
> > 
> >            if I use something like:
> > 
> >                try:
> >                        some statement
> >                except StandardError, e:
> >                        print e
> > 
> >        I got a whole string containing the sql executed an a description 
> > of the error. So what is e really?
>
>An "Exception" instance, more precisely, a "Psycopg" exception.
>
> > Can I get an error number, 
>
>No, as PostgreSQL does not report error numbers.
>
> > description and more information out of e? If not how can i do it?
>
>you can convert it into a string (with the built in function
>"str") and get something quite readable.
>
> >        2) Trying to specialize the exception treated I changed 
> > StandardError for IntegrityError/DatabaseError but in both cases i got:
> > 
> >        *Error Type: NameError*
> >         Error Value: global name 'DatabaseError/IntegrityError' is not 
> > defined*
>
>You must import them.
>
>
> > 
> >        Then i added to the script "import psycopg", with the same 
> > results and finally tried "import psycopg.Error" and got
> > 
> >        *Error Type: ImportError*
> >         Error Value: import of "psycopg.Error" is unauthorized
>
>Read the "README" of Python Scripts. It tells you how
>to allow import.
>
>
>Dieter
>
>_______________________________________________
>Zope-DB mailing list
>Zope-DB@zope.org
>http://mail.zope.org/mailman/listinfo/zope-db
>
>  
>


------------
¡Internet GRATIS es Yahoo! Conexión!
Usuario "yahoo", contraseña "yahoo". 
Desde Buenos Aires, 4004-1010.
Otras ciudades: http://conexion.yahoo.com.ar/avanzados.html