Hi, Short answer is there is no direct way of obtaining the offending line number in your template file. It would be helpful if we had access to the temporary .py file that Cheetah creates (for which the line number is provided) but unfortunately we don’t have access to that file. The best you can do is to infer from the error message. In the case above you are looking for a multiplication operation for which the left hand operand is (could be) None and the right hand operand is a float. Usually not too hard to spot possible problem locations (unless you have lots and lots of multiplication operators). Also, NoneType issues typically come from WeeWX fields/obs that are unexpectedly None, so something like $current.outTemp.raw * 1.2 would be a prime candidate (outTemp could be None for some reason) but 3.23 * 1.2 (no chance of None) is not nor would $current.outHumidity.raw * 2 (does not use a float).
If you are unfortunate enough to get an error message that is not very descriptive, or you have just too many possible error sites in your template, your only real option is to start breaking down your template into smaller chunks to find the location. I favour splitting the template in half, find the offending half template and then breaking that into halves and repeating the process, tedious but about the best you can do. This is a good incentive to make sure your code can tolerate variable/fields being None. Gary On Wednesday, 30 December 2020 at 06:54:22 UTC+10 WindnFog wrote: > Hi guys. I'm a little late converting from python 2.7 to python 3.7, but > true to my word last autumn, I'm now up to my elbows into it. It's going > well, and I'm using Matthews sftp extension to move it to my VPS web server > in Toronto, etc. This project will keep me busy for a while. > > My question is sort of simple. I have my index.html.tmpl heavily > customized, and I want to keep the features I've added over the past 4-5 > years. Some of them are causing it to choke because what I'm doing has to > be coded differently in Python 3.7. I'll figure all that out. The question > I have is: How do I find the line causing the error in index.html.tmpl? > Here's an example: > > *Dec 29 16:15:18 carrot python3[9457]: weewx[9457] INFO > weewx.imagegenerator: Generated 15 images for report SeasonsReport in 0.54 > seconds* > > *Dec 29 16:15:18 carrot python3[9457]: weewx[9457] INFO > weewx.reportengine: Copied 0 files to /var/www/html/weewx* > > *Dec 29 16:15:18 carrot python3[9457]: weewx[9457] ERROR > weewx.cheetahgenerator: Generate failed with exception '<class > 'TypeError'>'* > > *Dec 29 16:15:18 carrot python3[9457]: weewx[9457] ERROR > weewx.cheetahgenerator: **** Ignoring template > /etc/weewx/skins/Standard/index.html.tmpl* > > *Dec 29 16:15:18 carrot python3[9457]: weewx[9457] ERROR > weewx.cheetahgenerator: **** Reason: unsupported operand type(s) for *: > 'NoneType' and 'float'* > > *Dec 29 16:15:18 carrot python3[9457]: weewx[9457] ERROR > weewx.cheetahgenerator: **** Traceback (most recent call last):* > > *Dec 29 16:15:18 carrot python3[9457]: weewx[9457] ERROR > weewx.cheetahgenerator: **** File > "/usr/share/weewx/weewx/cheetahgenerator.py", line 323, in generate* > > *Dec 29 16:15:18 carrot python3[9457]: weewx[9457] ERROR > weewx.cheetahgenerator: **** unicode_string = compiled_template.respond()* > > *Dec 29 16:15:18 carrot python3[9457]: weewx[9457] ERROR > weewx.cheetahgenerator: **** File > "_etc_weewx_skins_Standard_index_html_tmpl.py", line 1135, in respond* > > *Dec 29 16:15:18 carrot python3[9457]: weewx[9457] ERROR > weewx.cheetahgenerator: **** TypeError: unsupported operand type(s) for *: > 'NoneType' and 'float'* > > *Dec 29 16:15:18 carrot python3[9457]: weewx[9457] INFO > weewx.cheetahgenerator: Generated 13 files for report StandardReport in > 0.67 seconds* > > *Dec 29 16:15:19 carrot python3[9457]: weewx[9457] INFO > weewx.imagegenerator: Generated 12 images for report StandardReport in 0.43 > seconds* > > *Dec 29 16:15:19 carrot python3[9457]: weewx[9457] INFO > weewx.reportengine: Copied 0 files to /var/www/html/weewx* > > This specific error doesn't matter because I can fix it if I can find the > offending like. Because index.html.tmpl goes through cheetah, I don't think > line 323 is the one causing the problem. I guessed correctly at a few, but > I know I'm going to get quite a few more. I need a way to narrow it down. > My version of index.html.tmpl is 867 lines, compared to the stock one of > 527 lines. > > - Paul VE1DX > -- 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 [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/e97bbef0-1603-4fcf-b625-149e9ef32625n%40googlegroups.com.
