[Zope] How manage error with zsql

2008-12-05 Thread Miguel Beltran R.
I tried to insert data using an zsql, insert fine How manage error with
zsql.
Before

   
   Data inserted!!!

   Error type:
   Error type:




Now (All files are ZPT)

[index_html]
...


...




[proyecto_alta.html]

   tal:condition="context/insert_data.zsql"
   tal:content="string: Data inserted!!!">




[error_insertar]
error=_['error']
if error.type==ZeroDivisionError:
return "Can't divide by zero."
else:
return """An error ocurred.
  Error type: %s
  Error value: %s""" % (error.type,
   error.value)


But say

Tipo Unauthorized  Valor You are not allowed to access 'type' in this
context  TraceBack

Traceback (innermost last):

   - Module ZPublisher.Publish, line 119, in publish
   - Module ZPublisher.mapply, line 88, in mapply
   - Module ZPublisher.Publish, line 42, in call_object
   - Module Shared.DC.Scripts.Bindings, line 313, in __call__
   - Module Shared.DC.Scripts.Bindings, line 350, in _bindAndExec
   - Module Products.PageTemplates.ZopePageTemplate, line 330, in _exec
   - Module Products.PageTemplates.ZopePageTemplate, line 427, in pt_render
   - Module Products.PageTemplates.PageTemplate, line 96, in pt_render
   - Module zope.pagetemplate.pagetemplate, line 115, in pt_render
   - Module zope.tal.talinterpreter, line 271, in __call__
   - Module zope.tal.talinterpreter, line 346, in interpret
   - Module zope.tal.talinterpreter, line 981, in do_onError_tal
   - Module zope.tal.talinterpreter, line 346, in interpret
   - Module zope.tal.talinterpreter, line 745, in do_insertStructure_tal
   - Module Products.PageTemplates.Expressions, line 199, in
   evaluateStructure
   - Module zope.tales.tales, line 696, in evaluate
   *URL: /ceed/finanza/proyecto/proyecto_alta.html*
   *Line 1, Column 0*
   *Expression: *
   *Names:*

   {'container': ,
'context': ,
'default': ,
'here': ,
'loop': {},
'nothing': None,
'options': {'args': ()},
'repeat': ,
'request': http://sic/finanza/proyecto/proyecto_alta.html>,
'root': ,
'template': ,
'traverse_subpath': [],
'user': }

   - Module zope.tales.expressions, line 217, in __call__
   - Module Products.PageTemplates.Expressions, line 139, in _eval
   - Module Products.PageTemplates.Expressions, line 91, in render
   - Module Products.PageTemplates.ZRPythonExpr, line 79, in call_with_ns
   - Module Shared.DC.Scripts.Bindings, line 327, in
   __render_with_namespace__
   - Module Shared.DC.Scripts.Bindings, line 350, in _bindAndExec
   - Module Products.PythonScripts.PythonScript, line 327, in _exec
   - Module None, line 2, in error_insertar
   **
   *Line 2*

Unauthorized: You are not allowed to access 'type' in this context

(Example taked from
http://www.plope.com/Books/2_7Edition/AppendixC.stx#2-28
)


-- 

Lo bueno de vivir un dia mas
es saber que nos queda un dia menos de vida
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] How manage error with zsql

2008-12-06 Thread robert rottermann
hi,

I think you should  write in a python script:

try:
  result = context.insert_data.zsql
  msg = 'data inserted'
except ZeroDivisionError:
  msg = 'ZeroDivisionError occured'

return msg

and in your tal you write:

> 
>tal:content="context/MyPythonscript">
>
> 
>

allways try to put logic in a python script. it is *far* easier than writing
complicated tal

robert

Miguel Beltran R. schrieb:
> I tried to insert data using an zsql, insert fine How manage error with
> zsql.
> Before
> 
>
>Data inserted!!!
> 
>Error type:
>Error type:
> 
> 
> 
> 
> Now (All files are ZPT)
> 
> [index_html]
> ...
> 
> 
> ...
> 
> 
> 
> 
> [proyecto_alta.html]
> 
>tal:condition="context/insert_data.zsql"
>tal:content="string: Data inserted!!!">
> 
> 
> 
> 
> [error_insertar]
> error=_['error']
> if error.type==ZeroDivisionError:
> return "Can't divide by zero."
> else:
> return """An error ocurred.
>   Error type: %s
>   Error value: %s""" % (error.type,
>error.value)
> 
> 
> But say
> 
> Tipo  Unauthorized
> Valor You are not allowed to access 'type' in this context
> TraceBack 
> 
> Traceback (innermost last):
> 
> * Module ZPublisher.Publish, line 119, in publish
> * Module ZPublisher.mapply, line 88, in mapply
> * Module ZPublisher.Publish, line 42, in call_object
> * Module Shared.DC.Scripts.Bindings, line 313, in __call__
> * Module Shared.DC.Scripts.Bindings, line 350, in _bindAndExec
> * Module Products.PageTemplates.ZopePageTemplate, line 330, in _exec
> * Module Products.PageTemplates.ZopePageTemplate, line 427, in pt_render
> * Module Products.PageTemplates.PageTemplate, line 96, in pt_render
> * Module zope.pagetemplate.pagetemplate, line 115, in pt_render
> * Module zope.tal.talinterpreter, line 271, in __call__
> * Module zope.tal.talinterpreter, line 346, in interpret
> * Module zope.tal.talinterpreter, line 981, in do_onError_tal
> * Module zope.tal.talinterpreter, line 346, in interpret
> * Module zope.tal.talinterpreter, line 745, in do_insertStructure_tal
> * Module Products.PageTemplates.Expressions, line 199, in
>   evaluateStructure
> * Module zope.tales.tales, line 696, in evaluate
>   *URL: /ceed/finanza/proyecto/proyecto_alta.html*
>   *Line 1, Column 0*
>   *Expression: *
>   *Names:*
> 
>   {'container': ,
>'context': ,
>'default': ,
>'here': ,
> 
>'loop': {},
>'nothing': None,
>'options': {'args': ()},
>'repeat':  0x02382828>,
>'request':  URL=http://sic/finanza/proyecto/proyecto_alta.html>,
> 
>'root': ,
>'template':  /ceed/finanza/proyecto/proyecto_alta.html>,
>'traverse_subpath': [],
>'user': }
> 
> * Module zope.tales.expressions, line 217, in __call__
> * Module Products.PageTemplates.Expressions, line 139, in _eval
> * Module Products.PageTemplates.Expressions, line 91, in render
> * Module Products.PageTemplates.ZRPythonExpr, line 79, in call_with_ns
> * Module Shared.DC.Scripts.Bindings, line 327, in
>   __render_with_namespace__
> * Module Shared.DC.Scripts.Bindings, line 350, in _bindAndExec
> * Module Products.PythonScripts.PythonScript, line 327, in _exec
> * Module None, line 2, in error_insertar
>   **
>   *Line 2*
> 
> Unauthorized: You are not allowed to access 'type' in this context
> 
> 
> 
> (Example taked from
> http://www.plope.com/Books/2_7Edition/AppendixC.stx#2-28
> )
> 
> 
> -- 
> 
> Lo bueno de vivir un dia mas
> es saber que nos queda un dia menos de vida
> 
> 
> 
> 
> ___
> Zope maillist  -  Zope@zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - 
>  http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope-dev )

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] How manage error with zsql

2008-12-06 Thread Andreas Jung



  **
  *Line 2*

Unauthorized: You are not allowed to access 'type' in this context



I think this is a know issue and be have a bugreport + patch already for 
that within the Launchpad bugtracker. However I cant the ticket number 
right now.


Andreas
begin:vcard
fn:Andreas Jung
n:Jung;Andreas
org:ZOPYX Ltd. & Co. KG
adr;quoted-printable:;;Charlottenstr. 37/1;T=C3=BCbingen;;72070;Germany
email;internet:[EMAIL PROTECTED]
title:CEO
tel;work:+49-7071-793376
tel;fax:+49-7071-7936840
tel;home:+49-7071-793257
x-mozilla-html:FALSE
url:www.zopyx.com
version:2.1
end:vcard

___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] How manage error with zsql

2008-12-06 Thread Dieter Maurer
robert rottermann wrote at 2008-12-6 17:15 +0100:
>I think you should  write in a python script:
>
>try:
>  result = context.insert_data.zsql

I expect (at least) two errors here. "context.insert_data()" has
a chance to work.

>  msg = 'data inserted'
>except ZeroDivisionError:
>  msg = 'ZeroDivisionError occured'



-- 
Dieter
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] How manage error with zsql

2008-12-08 Thread Miguel Beltran R.
I trying the next, but not work say " invalid syntax (Script (Python), line
11)"

2008/12/6 robert rottermann <[EMAIL PROTECTED]>

> hi,
>
> I think you should  write in a python script:
>
> try:
>  result = context.insert_data.zsql
>  msg = 'data inserted'
> except StandardError as e: <-- error here
>  msg = 'Error type %s. Value: %s' % (e.type, e.value)
>
> return msg
>
>
If change to


try:
   result=context.proyecto_alta_zsql()
   msg="Se incertaron los datos correctamente"
except StandardError, (e1,e2):
   msg = "Error valor %s y %s" % (e1,e2)
return msg

say
Tipo: Unauthorized
Valor: You are not allowed to access 'a particular str' in this context

(same error with type?)
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] How manage error with zsql

2008-12-09 Thread Dieter Maurer
Miguel Beltran R. wrote at 2008-12-8 21:01 -0600:
>I trying the next, but not work say " invalid syntax (Script (Python), line
>11)"
>
>2008/12/6 robert rottermann <[EMAIL PROTECTED]>
>
>> hi,
>>
>> I think you should  write in a python script:
>>
>> try:
>>  result = context.insert_data.zsql
>>  msg = 'data inserted'
>> except StandardError as e: <-- error here

The "as" should be "," instead.

After the removal of this error, you will meet the next two,
I have already pointed out in a message sent yesterday.

> ...
>If change to
>
>
>try:
>   result=context.proyecto_alta_zsql()
>   msg="Se incertaron los datos correctamente"
>except StandardError, (e1,e2):
>   msg = "Error valor %s y %s" % (e1,e2)
>return msg
>
>say
>Tipo: Unauthorized
>Valor: You are not allowed to access 'a particular str' in this context

Already much better :-)

In exceptional cases, the "(e1, e2)" might work. However,
usually, exceptions are no sequences and an exception cannot be matched
with "(e1, e2)".

Try "except StandardError, e:" (and, of course, change the following
line accordingly).


Whenever you get exceptions, you should look at the error
description in your "error_log" object (in the Zope "Root Folder" of the ZMI).
There, you can see (in the so called traceback) where the exception
has been raised. This is invaluable information.

Usually, "error_log" ignores "Unauthorized". Therefore, you must
temporarily reconfigure the "error_log" in order to get the information.
Should you have problems to understand it, come back with the information.



-- 
Dieter
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] How manage error with zsql

2008-12-09 Thread Miguel Beltran R.
>
>
> Whenever you get exceptions, you should look at the error
> description in your "error_log" object (in the Zope "Root Folder" of the
> ZMI).
> There, you can see (in the so called traceback) where the exception
> has been raised. This is invaluable information.
>
> --
> Dieter
>

Thanks, another question

is possible have a general except and inside show what type is?
in dtml was

...

  type:  value: 



-- 

Lo bueno de vivir un dia mas
es saber que nos queda un dia menos de vida
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] How manage error with zsql

2008-12-11 Thread Dieter Maurer
Miguel Beltran R. wrote at 2008-12-9 13:42 -0600:
>is possible have a general except and inside show what type is?
>in dtml was
>
>...
>
>  type:  value: 
>

According to the documentation (--> embedded online documentation (aka "Help")
--> Zope Help --> DTML Reference --> try), this is possible.

Note, however, that unqualified "try ... except ..." is dangerous,
everywhere, both in Python as well as in DTML.


Formerly, exceptions have been strings. Nowadays, exceptions are
class instances. I am not sure whether the DTML-try already
support non string exceptions.
If you observe problems, then this might be the reason.



-- 
Dieter
___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )