special character support

93 views
Skip to first unread message

peter

unread,
Jul 31, 2019, 2:27:19 AM7/31/19
to weewx-user
If I want to use special (non-English) characters like čžš, I get the following error:
Jul 31 08:21:16 weather weewx[22398]: cheetahgenerator: Generate failed with exception '<type 'exceptions.UnicodeDecodeError'>'
Jul 31 08:21:16 weather weewx[22398]: cheetahgenerator: **** Ignoring template /etc/weewx/skins/neowx/index.php.tmpl
Jul 31 08:21:16 weather weewx[22398]: cheetahgenerator: **** Reason: 'ascii' codec can't decode byte 0xc4 in position 10547: ordinal not in range(128)
Jul 31 08:21:16 weather weewx[22398]: ****  Traceback (most recent call last):
Jul 31 08:21:16 weather weewx[22398]: ****    File "/usr/share/weewx/weewx/cheetahgenerator.py", line 330, in generate
Jul 31 08:21:16 weather weewx[22398]: ****      filter=encoding,
Jul 31 08:21:16 weather weewx[22398]: ****    File "/usr/lib/python2.7/dist-packages/Cheetah/Template.py", line 1336, in __init__
Jul 31 08:21:16 weather weewx[22398]: ****      self._compile(source, file, compilerSettings=compilerSettings)
Jul 31 08:21:16 weather weewx[22398]: ****    File "/usr/lib/python2.7/dist-packages/Cheetah/Template.py", line 1637, in _compile
Jul 31 08:21:16 weather weewx[22398]: ****      keepRefToGeneratedCode=True)
Jul 31 08:21:16 weather weewx[22398]: ****    File "/usr/lib/python2.7/dist-packages/Cheetah/Template.py", line 772, in compile
Jul 31 08:21:16 weather weewx[22398]: ****      settings=(compilerSettings or {}))
Jul 31 08:21:16 weather weewx[22398]: ****    File "/usr/lib/python2.7/dist-packages/Cheetah/Compiler.py", line 1708, in __init__
Jul 31 08:21:16 weather weewx[22398]: ****      source = unicode(source)
Jul 31 08:21:16 weather weewx[22398]: ****  UnicodeDecodeError: '
ascii' codec can't decode byte 0xc4 in position 10547: ordinal not in range(128)

This only happens when I put these characters in the html/php template files. The weewx.conf or skin.conf use these characters for parameter definition and correctly include them into tags when the html file is being generated.

I use standard weewx configuration, no modifications to engine.py etc. I checked and the utf-8 is defined in the html templates.

I appreciate suggestions how to make this work.

gjr80

unread,
Jul 31, 2019, 10:23:16 AM7/31/19
to weewx-user
Hi,

In /etc/weewx/skins/neowx/skin.conf look for the line:

template = index.html.tmpl

under the [CheetahGenerator], it will probably be something like:

[CheetahGenerator]
....
[[ToDate]]
....
[[[xxxxxx]]]
template = index.html.tmpl

Is there an ‘encoding =‘ setting immediately below or above under the same [[[xxxxxx]]] stanza? If not try adding ‘encoding = utf8’, something like:

[CheetahGenerator]
....
[[ToDate]]
....
[[[xxxxxx]]]
template = index.html.tmpl
encoding = utf8

Save skin.conf and wait for the next report cycle to complete.

Gary

peter

unread,
Jul 31, 2019, 3:48:37 PM7/31/19
to weewx-user
Thanks for your suggestion.  I did have "encoding=utf8" defined, I rechecked once again.
I even moved it in the [[[day]]] section but it doesn't help, unfortunately.
My template file is actually index.php.tmpl. Does it make any difference?

gjr80

unread,
Aug 1, 2019, 9:20:10 AM8/1/19
to weewx-user
My mistake, too used to index.html.tmpl. The correct setting is of course the name of the template file being used. One more thought, there could be an override coming from weewx.conf. Could you post the [StdReport] stanza from weewx.conf as well as skin.conf from the neowx skin.

Gary

gjr80

unread,
Aug 1, 2019, 9:21:26 AM8/1/19
to weewx-user
Forgot to add, there should be no sensitive info in the [StdReport] stanza or skin.conf but do check before posting.

Gary

Thomas Keffer

unread,
Aug 1, 2019, 8:49:41 PM8/1/19
to weewx-user
Check for an #encoding directive at the top of your template. For example, index.html.tmpl in the Standard template uses:

#errorCatcher Echo
##
## Specifying an encoding of UTF-8 is usually safe:
#encoding UTF-8
##
<!DOCTYPE HTML>
<html lang="en">
<head>
## This choice should match the #encoding directive above
<meta charset="UTF-8">

-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/954066dc-08fe-4bf0-b3dc-08604ef25064%40googlegroups.com.

peter

unread,
Aug 2, 2019, 2:23:29 AM8/2/19
to weewx-user
Thank you Thomas, your instruction fixes the issue! My template was missing the #encoding UTF-8. I entered this row above the <!DOCTYPE HTML>.
(y)
Many thanks.


To unsubscribe from this group and stop receiving emails from it, send an email to weewx...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages