Weird error with days_ago in 3.8.0

77 views
Skip to first unread message

wxstor...@gmail.com

unread,
Apr 4, 2023, 8:16:44 PM4/4/23
to weewx-user
I started getting an type error April 1st using days_ago. "Must be a real number, not str". But it is an integer that I am requesting from the database as I am requesting the raw dateTime. Now it works on some days and not others, like 357 days ago but not 360 days. Code from the template and the error is below. What am I missing here? 

#set $n = 357
 <div class="card" >
            <h1><i class="fa-solid fa-clock-rotate-left" ></i> Last $days_ago($days_ago=$n).dateTime.raw </h1>
 </div>

Apr  3 17:14:21 CW9009 weewx[618] INFO weewx.manager: Added record 2023-04-03 17:14:00 MDT (1680563640) to database 'weewx.sdb'
Apr  3 17:14:21 CW9009 weewx[618] INFO weewx.manager: Added record 2023-04-03 17:14:00 MDT (1680563640) to daily summary in 'weewx.sdb'
Apr  3 17:14:21 CW9009 weewx[618] INFO user.weatherflowudp: Listening for UDP broadcasts to IP address <broadcast> on port 50222, with timeout 60 and share_socket False...
Apr  3 17:14:22 CW9009 weewx[618] INFO weewx.restx: OWM: Published record 2023-04-03 17:14:00 MDT (1680563640)
Apr  3 17:14:23 CW9009 weewx[618] ERROR weewx.cheetahgenerator: Evaluation of template /etc/weewx/skins/Sofaskin/index.html.tmpl failed with exception '<class 'TypeError'>'
Apr  3 17:14:23 CW9009 weewx[618] ERROR weewx.cheetahgenerator: **** Ignoring template /etc/weewx/skins/Sofaskin/index.html.tmpl
Apr  3 17:14:23 CW9009 weewx[618] ERROR weewx.cheetahgenerator: **** Reason: must be real number, not str
Apr  3 17:14:23 CW9009 weewx[618] ERROR weewx.cheetahgenerator: ****  Traceback (most recent call last):
Apr  3 17:14:23 CW9009 weewx[618] ERROR weewx.cheetahgenerator: ****    File "/usr/share/weewx/weewx/cheetahgenerator.py", line 348, in generate
Apr  3 17:14:23 CW9009 weewx[618] ERROR weewx.cheetahgenerator: ****      unicode_string = compiled_template.respond()
Apr  3 17:14:23 CW9009 weewx[618] ERROR weewx.cheetahgenerator: ****    File "_etc_weewx_skins_Sofaskin_index_html_tmpl.py", line 1011, in respond
Apr  3 17:14:23 CW9009 weewx[618] ERROR weewx.cheetahgenerator: ****    File "/usr/share/weewx/weewx/cheetahgenerator.py", line 823, in filter
Apr  3 17:14:23 CW9009 weewx[618] ERROR weewx.cheetahgenerator: ****      filtered = six.text_type(val)
Apr  3 17:14:23 CW9009 weewx[618] ERROR weewx.cheetahgenerator: ****    File "/usr/share/weewx/weewx/tags.py", line 461, in __str__
Apr  3 17:14:23 CW9009 weewx[618] ERROR weewx.cheetahgenerator: ****      return str(vh)
Apr  3 17:14:23 CW9009 weewx[618] ERROR weewx.cheetahgenerator: ****    File "/usr/share/weewx/weewx/units.py", line 1019, in __str__
Apr  3 17:14:23 CW9009 weewx[618] ERROR weewx.cheetahgenerator: ****      s = self.toString()
Apr  3 17:14:23 CW9009 weewx[618] ERROR weewx.cheetahgenerator: ****    File "/usr/share/weewx/weewx/units.py", line 1012, in toString
Apr  3 17:14:23 CW9009 weewx[618] ERROR weewx.cheetahgenerator: ****      s = self.formatter.toString(self.value_t, self.context, addLabel=addLabel,
Apr  3 17:14:23 CW9009 weewx[618] ERROR weewx.cheetahgenerator: ****    File "/usr/share/weewx/weewx/units.py", line 698, in toString
Apr  3 17:14:23 CW9009 weewx[618] ERROR weewx.cheetahgenerator: ****      s = self._to_string(val_t, context, addLabel, useThisFormat, None_string, localize)
Apr  3 17:14:23 CW9009 weewx[618] ERROR weewx.cheetahgenerator: ****    File "/usr/share/weewx/weewx/units.py", line 774, in _to_string
Apr  3 17:14:23 CW9009 weewx[618] ERROR weewx.cheetahgenerator: ****      val_str = locale.format_string(format_string, val_t[0])
Apr  3 17:14:23 CW9009 weewx[618] ERROR weewx.cheetahgenerator: ****    File "/usr/lib/python3.9/locale.py", line 234, in format_string
Apr  3 17:14:23 CW9009 weewx[618] ERROR weewx.cheetahgenerator: ****      new_val.append(_format(perc.group(),
Apr  3 17:14:23 CW9009 weewx[618] ERROR weewx.cheetahgenerator: ****    File "/usr/lib/python3.9/locale.py", line 187, in _format
Apr  3 17:14:23 CW9009 weewx[618] ERROR weewx.cheetahgenerator: ****      formatted = percent % value
Apr  3 17:14:23 CW9009 weewx[618] ERROR weewx.cheetahgenerator: ****  TypeError: must be real number, not str
Apr  3 17:14:24 CW9009 weewx[618] INFO weewx.cheetahgenerator: Generated 10 files for report StandardReport in 2.68 seconds
Apr  3 17:14:26 CW9009 weewx[618] INFO weewx.imagegenerator: Generated 12 images for report StandardReport in 2.18 seconds
Apr  3 17:14:26 CW9009 weewx[618] INFO weewx.reportengine: Copied 0 files to /var/www/html/weewx
Apr  3 17:14:34 CW9009 weewx[618] INFO weewx.reportengine: ftpgenerator: Ftp'd 23 files in 7.63 seconds


Tom Keffer

unread,
Apr 4, 2023, 8:45:16 PM4/4/23
to weewx...@googlegroups.com
I don't know anything about the Sofaskin, but I do know that the line you posted is unlikely to be causing the error. A ".raw" value is not formatted at all. It is simply passed through. Of course, some magic might be happening in the first $days_ago, so it's possible I am wrong.

Finding Cheetah errors can be very tough. Frequently, I have resorted to binary searches through the template: Comment out half the template and see if it was the half causing the error. Keep halving the offending part until you can isolate the line. 

--
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/e01c712d-a053-43b8-a1d3-0e00bcb87391n%40googlegroups.com.
Message has been deleted
Message has been deleted

jterr...@gmail.com

unread,
Apr 5, 2023, 2:05:35 PM4/5/23
to weewx-user
No sure if this is related to your errors, but it looks like the tag $days_ago($days_ago=$n).dateTime.raw is not correct.

According to weewx documentation, ($days_ago=x)  should be used with the day aggregation period   : $day($days_ago=$n).dateTime.raw 



Tom Keffer

unread,
Apr 5, 2023, 8:18:25 PM4/5/23
to weewx...@googlegroups.com
Definitely. I had assumed it was some weird Sofaskin thing, but maybe no.

--
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.

wxstor...@gmail.com

unread,
Apr 6, 2023, 11:33:07 AM4/6/23
to weewx-user
Thanks all for your input.
I was able to determine a couple of issues with my testing efforts and the database that caused the issues. I didn't realize that cheetah would still try to execute the commented out code which made troubleshooting much harder. Once I deleted the code I was able to determine it was a database issue. The issue ended up being that some daily achieve data was missing in the database. Not sure how that happened but once I rebuilt the daily achieve for 2022 it worked fine. 

Thanks for you suggestions! 
Reply all
Reply to author
Forward
0 new messages