Problem with Greek mu character in Python upload to emoncms

52 views
Skip to first unread message

bgra...@umw.edu

unread,
Feb 18, 2024, 4:13:48 PM2/18/24
to weewx-user
Hello,
I am running weewx 4.10.2 (setup.py) on Ubuntu and Python3. All is fine except:

I have data from a Geiger counter coming into weewx (Standard page) and being displayed in microSeverts, using the µSv mu character. Before adding this mu character, I was uploading to my emoncms server using the MQTT  extension (0.17). Things have stopped being uploaded (see debug errors below) to emoncms.
Is it possible to filter out the Geiger data as I don't need it going to emoncms, or is it possible to get the "µ" character accepted for the upload? I'm not a programmer so am somewhat lost here.  Thanks in advance.
Cheers,

weewx.log:
Feb 18 12:00:16 n4mrv weewx[39438] DEBUG weewx.reportengine: Running report 'StandardReport'
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: EmonCMS: Unexpected exception of type <class 'UnicodeEncodeError'>
Feb 18 12:00:16 n4mrv weewx[39438] DEBUG weewx.reportengine: Found configuration file /home/weewx/skins/Standard/skin.conf for report 'StandardReport'
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: *** Traceback (most recent call last):
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***   File "/home/weewx/bin/weewx/restx.py", line 382, in run_loop
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***     self.process_record(_record, dbmanager)
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***   File "/home/weewx/bin/user/emoncms.py", line 288, in process_record
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***     self.post_with_retries(req)
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***   File "/home/weewx/bin/weewx/restx.py", line 477, in post_with_retries
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***     _response = self.post_request(request, data)
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***   File "/home/weewx/bin/weewx/restx.py", line 541, in post_request
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***     _response = urllib.request.urlopen(request, data=data_bytes, timeout=self.timeout)
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***   File "/usr/lib/python3.10/urllib/request.py", line 216, in urlopen
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***     return opener.open(url, data, timeout)
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***   File "/usr/lib/python3.10/urllib/request.py", line 519, in open
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***     response = self._open(req, data)
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***   File "/usr/lib/python3.10/urllib/request.py", line 536, in _open
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***     result = self._call_chain(self.handle_open, protocol, protocol +
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***   File "/usr/lib/python3.10/urllib/request.py", line 496, in _call_chain
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***     result = func(*args)
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***   File "/usr/lib/python3.10/urllib/request.py", line 1377, in http_open
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***     return self.do_open(http.client.HTTPConnection, req)
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***   File "/usr/lib/python3.10/urllib/request.py", line 1348, in do_open
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***     h.request(req.get_method(), req.selector, req.data, headers,
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***   File "/usr/lib/python3.10/http/client.py", line 1283, in request
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***     self._send_request(method, url, body, headers, encode_chunked)
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***   File "/usr/lib/python3.10/http/client.py", line 1294, in _send_request
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***     self.putrequest(method, url, **skips)
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***   File "/usr/lib/python3.10/http/client.py", line 1132, in putrequest
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***     self._output(self._encode_request(request))
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***   File "/usr/lib/python3.10/http/client.py", line 1212, in _encode_request
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: ***     return request.encode('ascii')
Feb 18 12:00:16 n4mrv weewx[39438] ERROR weewx.restx: *** UnicodeEncodeError: 'ascii' codec can't encode character '\xb5' in position 644: ordinal not in range(128)
Feb 18 12:00:16 n4mrv weewx[39438] CRITICAL weewx.restx: EmonCMS: Thread terminating. Reason: 'ascii' codec can't encode character '\xb5' in position 644: ordinal not in range(128)

p q

unread,
Feb 18, 2024, 5:09:32 PM2/18/24
to weewx...@googlegroups.com
My guess is you need to use utf-8 encoding not ascii.
something like
<meta charset="UTF-8">
 in your HTML header.

By the way, I'm interested in adding a geiger counter to my system. Where did you get yours?


--
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/624ac5d6-4645-44b2-b925-5f95927154c1n%40googlegroups.com.


--
Peter Quinn
(415)794-2264

bgra...@umw.edu

unread,
Feb 18, 2024, 5:26:00 PM2/18/24
to weewx-user
Thanks, p q. My page display is ok but the MQTT data uploaded from weewx to emoncms is tripped up by the mu character. It doesn’t like the >128 ASCII code. 
I use the radmon plus Geiger counter which has an MQTT option plus it uploads to radmon.org.
Bob
Reply all
Reply to author
Forward
0 new messages