Re: [Zope] How manage error with zsql
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 dtml-try ... dtml-except type:dtml-var error_type value: dtml-var error_value /dtml-try 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 )
Re: [Zope] How manage error with zsql
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
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 dtml-try ... dtml-except type:dtml-var error_type value: dtml-var error_value /dtml-try -- 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
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. brValue: %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
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: div tal:content=context/MyPythonscript /div 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 dtml-try dtml-call insert_data Data inserted!!! dtml-except Error type:dtml-var error_type Error type:dtml-var error_value /dtml-try Now (All files are ZPT) [index_html] ... form action=proyecto_alta.html input type=text name=field1 id=field1 / ... input type=text name=field2 id=field2 / /form [proyecto_alta.html] div tal:on-error=structure here/error_insertar tal:condition=context/insert_data.zsql tal:content=string: Data inserted!!! /div [error_insertar] error=_['error'] if error.type==ZeroDivisionError: return pCan't divide by zero./p else: return pAn error ocurred./p pError type: %s/p pError value: %s/p % (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: PathExpr standard:u'here/error_insertar'* *Names:* {'container': Folder at /ceed/finanza/proyecto, 'context': Folder at /ceed/finanza/proyecto, 'default': object object at 0x0075A528, 'here': Folder at /ceed/finanza/proyecto, 'loop': {}, 'nothing': None, 'options': {'args': ()}, 'repeat': Products.PageTemplates.Expressions.SafeMapping object at 0x02382828, 'request': HTTPRequest, URL=http://sic/finanza/proyecto/proyecto_alta.html, 'root': Application at , 'template': ZopePageTemplate at /ceed/finanza/proyecto/proyecto_alta.html, 'traverse_subpath': [], 'user': User 'admin'} * 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 *PythonScript at /ceed/finanza/proyecto/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 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
*PythonScript at /ceed/finanza/proyecto/error_insertar* *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
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 )