[Zoo-discuss] try except in error apache2
Fenoy Gerald
gerald.fenoy at geolabs.fr
Wed Feb 12 07:46:39 PST 2014
Hello Quang,
sorry for late answer.
The print function should work the same as from any Python interpreter, meaning that you can use it in the same way. Nevertheless, the print function will imply that the message to be printed will be on the standard output not on the standard error stream so it will imply that except from command line your request will dramatically failed.
For dealing with error messages there is two different ways. The first one consist simply to display debug message on the standard error stream (which is the apache error log file in case you are using ZOO-Kernel as CGI), for this you can simply use the following code:
Python 2.X:
print >> sys.stderr,message
Python 3.X:
print(message, file=sys.stderr)
The second one, is when your service failed, in such a case you should use the message map located in the [lenv] section (dynamically created, cf. [1] for more info) of the first parameter maps. So from your service you may use something like this:
def myService(conf,in,out):
conf[["lenv’]["message »]="my error message"
return zoo.SERVICE_FAILED
I hope this helps.
Best regards,
[1] http://svn.zoo-project.org/trac/browser/trunk/zoo-project/zoo-kernel/zoo_service_loader.c?rev=453#L2140
Le 11 févr. 2014 à 17:10, truongxuan quang <truongxuanquang at yahoo.com> a écrit :
> Dear list
>
> I have some problem with writing an error in error.log. Currently in ZOO-ServerProvider (*.py) I used a lot of: try: ... except:
> Eg: try:
> open_url()
> except:
> print (type_of_error)
> But ZOO-Kernel seem doesn't with directly with "print function", moreover I would to write every error if they occur in the log file (error.log) or some where else.
> I don't have any experience in this section. Can anyone kind help?
>
> Many thanks
>
> Quang
Gérald Fenoy
gerald.fenoy at geolabs.fr
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 204 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.osgeo.org/pipermail/zoo-discuss/attachments/20140212/8bffb957/attachment.pgp>
More information about the Zoo-discuss
mailing list