weewx.cheetahgenerator debug

157 views
Skip to first unread message

František Slimařík

unread,
Apr 17, 2021, 12:15:00 AM4/17/21
to weewx-user

Hello,

is there any possibility how to debug weewx output to identify line in template which causes error? I had to restore snapshot of my machine from previous day backup and discovered this error which wasn't visible before. I am parsing API from openweather on several places and don't wanna go line by line and test. Thanks for hints.

Apr 17 06:10:17 new-weather-machine journal: weewx[5310] INFO weewx.restx: PWSWeather: Published record 2021-04-17 06:10:00 CEST (1618632600)
Apr 17 06:10:18 new-weather-machine journal: weewx[5310] INFO weewx.restx: OWM: Published record 2021-04-17 06:10:00 CEST (1618632600)
Apr 17 06:10:19 new-weather-machine journal: weewx[5310] ERROR weewx.cheetahgenerator: Generate failed with exception '<type 'exceptions.ValueError'>'
Apr 17 06:10:19 new-weather-machine journal: weewx[5310] ERROR weewx.cheetahgenerator: **** Ignoring template /etc/weewx/skins/neowx/index.html.tmpl
Apr 17 06:10:19 new-weather-machine journal: weewx[5310] ERROR weewx.cheetahgenerator: **** Reason: could not convert string to float:
Apr 17 06:10:19 new-weather-machine journal: weewx[5310] ERROR weewx.cheetahgenerator: ****  Traceback (most recent call last):
Apr 17 06:10:19 new-weather-machine journal: weewx[5310] ERROR weewx.cheetahgenerator: ****    File "/usr/share/weewx/weewx/cheetahgenerator.py", line 326, in generate
Apr 17 06:10:19 new-weather-machine journal: weewx[5310] ERROR weewx.cheetahgenerator: ****      unicode_string = compiled_template.respond()
Apr 17 06:10:19 new-weather-machine journal: weewx[5310] ERROR weewx.cheetahgenerator: ****    File "cheetah__etc_weewx_skins_neowx_index_html_tmpl_1618632018_51_95540.py", line 1506, in respond
Apr 17 06:10:19 new-weather-machine journal: weewx[5310] ERROR weewx.cheetahgenerator: ****  ValueError: could not convert string to float:
Apr 17 06:10:25 new-weather-machine journal: weewx[5310] INFO weewx.cheetahgenerator: Generated 15 files for report StandardReport in 7.57 seconds
Apr 17 06:10:25 new-weather-machine journal: weewx[5310] INFO weewx.reportengine: Copied 0 files to /var/www/html/weewx

gjr80

unread,
Apr 17, 2021, 12:32:47 AM4/17/21
to weewx-user
Hi,

Unfortunately sometimes Cheetah gives only limited info and often the best you can do is try to deduce from the error message where or what the error is. As you have no doubt found you cannot use the line number referred to in the error trace, that is a line number in temporary file created by Cheetah and we don't have access to that file.

In your case I would start by looking in your template for any explicit uses of float() to convert a string to a float. The argument of the float() call is something that is impossible to convert to a float. It's possible the float() could be in some WeeWX code called by the CheetahGenerator but I suspect not or you would have seen a different error trace. One approach is to start commenting out template code to track down the location of the error.

It's hard to offer much more advice without seeing your template code. Again not seeing your code and not knowing what you are trying to do, but this is one reason why parsing data from an external source is often best done in a Search List Extension or a WeeWX service where you can use pure python that is far easier to debug. Templates are usually best left to just formatting output wherever possible.

Gary

František Slimařík

unread,
Apr 17, 2021, 1:06:49 AM4/17/21
to weewx-user
Hi Gary,

I was afraid of such a answer :) Yeah, unfortunately I've put too much code into template instead of WeeWX service.

Thanks anyway :)

Dne sobota 17. dubna 2021 v 6:32:47 UTC+2 uživatel gjr80 napsal:

Graham Eddy

unread,
Apr 17, 2021, 1:13:54 AM4/17/21
to weewx...@googlegroups.com
it would be really helpful if the temporary file created by cheetah was not deleted when an error occurred

Tom Keffer

unread,
Apr 17, 2021, 8:34:49 AM4/17/21
to weewx-user
You can use the cheetah utility "cheetah" to compile the template, then look at that. Unfortunately, it is fussy about file names. The pattern looks something like this:

cp index.html.tmpl index.tmpl
cheetah compile index.tmpl

Then look at the resultant file index.py. The lines will be cryptic, but the line numbers will be correct.

-tk

--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/F90C894F-4EA5-49DD-B3A5-D5F091010060%40gmail.com.

mwall

unread,
Apr 17, 2021, 9:34:44 AM4/17/21
to weewx-user
On Saturday, April 17, 2021 at 1:13:54 AM UTC-4 graha...@gmail.com wrote:
it would be really helpful if the temporary file created by cheetah was not deleted when an error occurred

agreed.  i tried to make it do that years ago, and it would not cooperate without a modification to its source code.
 

František Slimařík

unread,
Apr 17, 2021, 3:14:18 PM4/17/21
to weewx-user
OK, Gary was right. Because I restored snapshot of VM from the morning I had there some "N/A" values which I tried to parse with float() (for my HighCharts graph). Anyway, I wanna thank you for good piece of software. Since I publish data to WU it was easy to restore them and I am back on track :)
Dne sobota 17. dubna 2021 v 15:34:44 UTC+2 uživatel mwall napsal:
Reply all
Reply to author
Forward
0 new messages