After update to version 4.1 - Imagegenerator UnicodeEncodeError: 'ascii' codec can't encode character

91 views
Skip to first unread message

dani.mac...@gmail.com

unread,
Oct 8, 2020, 6:55:59 AM10/8/20
to weewx-user
Hello,

I finally updated yesterday to version 4.1. Unfortunately I get the well known UnicodeEncodeError in imagegenerator when processing spanish characters. I have tried all the tips I have found (reinstalling the font, checking locale, etc). 

It is weird, because some characters are being correctly generated (í) but some others don't (ó). And finally a character cannot not be generated at all and imagegenerator fails:


Oct  8 12:52:06 TrastoRaspberry weewx[25710] ERROR weewx.reportengine: Caught unrecoverable exception in generator 'user.translategenerator.ImageGeneratorTranslated'
Oct  8 12:52:06 TrastoRaspberry weewx[25710] ERROR weewx.reportengine:         ****  'ascii' codec can't decode byte 0xc3 in position 7: ordinal not in range(128)
Oct  8 12:52:06 TrastoRaspberry weewx[25710] ERROR weewx.reportengine:         ****  Traceback (most recent call last):
Oct  8 12:52:06 TrastoRaspberry weewx[25710] ERROR weewx.reportengine:         ****    File "/usr/share/weewx/weewx/reportengine.py", line 197, in run
Oct  8 12:52:06 TrastoRaspberry weewx[25710] ERROR weewx.reportengine:         ****      obj.start()
Oct  8 12:52:06 TrastoRaspberry weewx[25710] ERROR weewx.reportengine:         ****    File "/usr/share/weewx/weewx/reportengine.py", line 280, in start
Oct  8 12:52:06 TrastoRaspberry weewx[25710] ERROR weewx.reportengine:         ****      self.run()
Oct  8 12:52:06 TrastoRaspberry weewx[25710] ERROR weewx.reportengine:         ****    File "/usr/share/weewx/weewx/imagegenerator.py", line 41, in run
Oct  8 12:52:06 TrastoRaspberry weewx[25710] ERROR weewx.reportengine:         ****      self.genImages(self.gen_ts)
Oct  8 12:52:06 TrastoRaspberry weewx[25710] ERROR weewx.reportengine:         ****    File "/usr/share/weewx/weewx/imagegenerator.py", line 263, in genImages
Oct  8 12:52:06 TrastoRaspberry weewx[25710] ERROR weewx.reportengine:         ****      image = plot.render()
Oct  8 12:52:06 TrastoRaspberry weewx[25710] ERROR weewx.reportengine:         ****    File "/usr/share/weewx/weeplot/genplot.py", line 200, in render
Oct  8 12:52:06 TrastoRaspberry weewx[25710] ERROR weewx.reportengine:         ****      self._renderTopBand(draw)
Oct  8 12:52:06 TrastoRaspberry weewx[25710] ERROR weewx.reportengine:         ****    File "/usr/share/weewx/weeplot/genplot.py", line 404, in _renderTopBand
Oct  8 12:52:06 TrastoRaspberry weewx[25710] ERROR weewx.reportengine:         ****      top_label = ' '.join([line.label for line in self.line_list])
Oct  8 12:52:06 TrastoRaspberry weewx[25710] ERROR weewx.reportengine:         ****  UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 7: ordinal not in range(128)
Oct  8 12:52:06 TrastoRaspberry weewx[25710] ERROR weewx.reportengine:         ****  Generator terminated


Can anybody give me a hint of where can be the problem?

Thanks!

Daniel

Tom Keffer

unread,
Oct 8, 2020, 7:50:49 AM10/8/20
to weewx-user
Hello, Daniel.

What version of Python are you using?

What is 'user.translategenerator.ImageGeneratorTranslated'? It is not part of WeeWX. Most likely, it is creating image labels, which are not in unicode.

-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/67de28de-dab7-49c4-8cb6-b21ddfc43399n%40googlegroups.com.

Dani Macías Perea

unread,
Oct 8, 2020, 7:59:41 AM10/8/20
to weewx...@googlegroups.com
Thanks for your answer Tom.
Sorry, I tought ImageGeneratorTranslated was part of WeeWX. It is an skin from Nick Dajda (brewster76) https://github.com/brewster76/fuzzy-archer/blob/master/bin/user/translategenerator.py
Using Python 2.7.13.


You received this message because you are subscribed to a topic in the Google Groups "weewx-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/weewx-user/iMdHE0iZnrg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/CAPq0zEA__m-_vPJe_nhSECVXqB-y3e2GRj6Jf0ogrOQJf8uAsw%40mail.gmail.com.

Tom Keffer

unread,
Oct 8, 2020, 8:25:32 AM10/8/20
to weewx-user
Looking (briefly) through the code, it looks like Nick did not port it to Python 2. In particular, when he opens up the language configuration file, he did not specify an encoding, so the results will not be in Unicode.

Try changing line 87 from

language_dict = ConfigObj(language_config_path)

to

language_dict = ConfigObj(language_config_path, encoding='utf-8', default_encoding='utf-8')

No guarantees.


Dani Macías Perea

unread,
Oct 8, 2020, 8:40:59 AM10/8/20
to weewx...@googlegroups.com
Worked like a charm.

Thank you very much Sir! 
I will create a pull request with the changes so other people can find easily the solution.

Regards,

Daniel


Reply all
Reply to author
Forward
0 new messages