Page 1 of 2
When receiving UDP with nordic characters?
Posted: Tue Nov 15, 2016 5:19 am
by skribb
Code: Select all
06:15:05 error: uncaptured python exception, closing channel <eg.CorePluginModule.Broadcaster.Server connected 192.168.0.104:33333 at 0x47d2800> (<type 'exceptions.UnicodeDecodeError'>:'ascii' codec can't decode byte 0xc3 in position 12: ordinal not in range(128) [asyncore.pyc|read|76] [asyncore.pyc|handle_read_event|416] [C:\Program Files (x86)\EventGhost\plugins\Broadcaster\__init__.py|handle_read|95] [C:\Program Files (x86)\EventGhost\eg\Classes\PluginBase.py|TriggerEvent|133] [C:\Program Files (x86)\EventGhost\eg\Classes\EventThread.py|TriggerEvent|78] [C:\Program Files (x86)\EventGhost\eg\Classes\EventGhostEvent.py|__init__|84])
Now, I suppose this error is because of the nordic characters not being part of the Unicode charset or whatever? Or is it something else
Re: When receiving UDP with nordic characters?
Posted: Tue Nov 15, 2016 5:46 am
by kgschlosser
well this is a hex of the character you are receiving
0xc3
i do not know if that hex value is a unicode value or not. but i am sure with some google searching we can find out
Re: When receiving UDP with nordic characters?
Posted: Tue Nov 15, 2016 6:07 am
by kgschlosser
ok the 0xc3 is in fact a unicode character. it's a capital A with e Tilda (~) above it. I have done a little bit of reading on this. and i think there is a way to get unicode support into EG for the log. but as to how much work it will be i am unsure due to how EG uses events to trigger actions. it's one thing to simply get it to display properly in the log. it's something completely different as to how to handle having eg search for an event in the tree. it' s beyond my knowledge at present. and it would also be something that would have to be done at the core level. but the broadcaster plugin can be modified to work properly simply by going into the plugin and at line 91-99 this the the current code. now this is a oversimplified way of correcting the socket close problem. and the characters may not appear properly. don't know read below.
THIS HAS NOT BEEN TESTED.
Code: Select all
if (not my_addr) or self.selfBroadcast:
bits = data.split(str(self.payDelim))
commandSize=len(bits)
if commandSize==1:
self.plugin.TriggerEvent(bits[0])
if commandSize==2:
self.plugin.TriggerEvent(bits[0],bits[1])
if commandSize>2:
self.plugin.TriggerEvent(bits[0],bits[1:])
and it needs to be changed to this
Code: Select all
# quick and dirty hack to stop the broadcaster plugin from disconnecting sockets
# due to unicode encoded data
if (not my_addr) or self.selfBroadcast:
bits = data.split(str(self.payDelim))
commandSize=len(bits)
if commandSize==1:
self.plugin.TriggerEvent(str(bits[0]))
if commandSize==2:
self.plugin.TriggerEvent(str(bits[0]), bits[1])
if commandSize>2:
self.plugin.TriggerEvent(str(bits[0]), bits[1:])
Re: When receiving UDP with nordic characters?
Posted: Tue Nov 15, 2016 4:05 pm
by skribb
This is so weird because the message that is being received is t1.SUNRISE which is what my tablet sends to EG to start my morning alarm stuff in EG. Which works 99% of the time..... I'm not even sending a à character (Ä is nordic tho, but i'm not using that one either.....)
thanks for your fixing attempt KG, I will switch out the snippet you mentioned and see if my problem is ameliorated by that.

Re: When receiving UDP with nordic characters?
Posted: Tue Nov 15, 2016 6:40 pm
by kgschlosser
let me know if it works or not... i am curious to know
Re: When receiving UDP with nordic characters?
Posted: Tue Nov 15, 2016 7:27 pm
by skribb
kgschlosser wrote:let me know if it works or not... i am curious to know
Why certainly! that is the least I can do
I'm eagerly awating tomorrow's morning alarm. Crossing my thumbs and everything

Re: When receiving UDP with nordic characters?
Posted: Wed Nov 16, 2016 2:21 am
by kgschlosser
it should do the trick. if not i can key something up to do a right proper decode. on it.
Re: When receiving UDP with nordic characters?
Posted: Wed Nov 16, 2016 8:22 pm
by skribb
Status updatE:
No error so far

Re: When receiving UDP with nordic characters?
Posted: Thu Nov 17, 2016 3:54 am
by kgschlosser
it's a sloppy hack. and not the proper way. but it should work for ya.
and it's easy
Re: When receiving UDP with nordic characters?
Posted: Thu Nov 17, 2016 5:47 am
by skribb
kgschlosser wrote:it's a sloppy hack. and not the proper way. but it should work for ya.
and it's easy
Don't worry about it. That's exactly my style

Re: When receiving UDP with nordic characters?
Posted: Sat Nov 19, 2016 5:29 pm
by skribb
I bring grave news, fellow tinkerer....
Code: Select all
2016-11-19 09:04:44 INFO: error: uncaptured python exception, closing channel <eg.CorePluginModule.Broadcaster.Server connected 192.168.0.104:33333 at 0x47d6940> (<type 'exceptions.UnicodeDecodeError'>:'ascii' codec can't decode byte 0xc3 in position 10: ordinal not in range(128) [asyncore.pyc|read|76] [asyncore.pyc|handle_read_event|416] [C:\Program Files (x86)\EventGhost\plugins\Broadcaster\__init__.py|handle_read|95] [C:\Program Files (x86)\EventGhost\eg\Classes\PluginBase.py|TriggerEvent|133] [C:\Program Files (x86)\EventGhost\eg\Classes\EventThread.py|TriggerEvent|78] [C:\Program Files (x86)\EventGhost\eg\Classes\EventGhostEvent.py|__init__|84])
Maybe i should try what you wrote here:
viewtopic.php?f=4&t=8116&hilit=asyncore&start=45#p40878
For now I will experiment with automatically restarting broadcaster on Schdedulghost
Re: When receiving UDP with nordic characters?
Posted: Sat Nov 19, 2016 7:40 pm
by kgschlosser
do this it's the much better way and not a sloppy hack
give it a shot
HAS NOT BEEN TESTED
Code: Select all
if (not my_addr) or self.selfBroadcast:
bits = data.split(str(self.payDelim))
commandSize=len(bits)
if commandSize:
suffix = bits[0]
if commandSize == 2:
payload = bits[1]
elif commandSize > 2:
payload = bits[1:]
else:
payload = None
try:
self.plugin.TriggerEvent(suffix=str(suffix), payload=payload)
except UnicodeDecodeError:
self.plugin.TriggerEvent(suffix=suffix.encode('utf8'), payload=payload)
Re: When receiving UDP with nordic characters?
Posted: Sat Nov 19, 2016 7:44 pm
by kgschlosser
you may or may not have to change the suffix.decode('utf8') to suffix.decode('latin1')
this unicode stuff i have not really messed with. so this is a learning process for the both of us
Re: When receiving UDP with nordic characters?
Posted: Sat Nov 19, 2016 9:50 pm
by davidmark
kgschlosser wrote:you may or may not have to change the suffix.decode('utf8') to suffix.decode('latin1')
this unicode stuff i have not really messed with. so this is a learning process for the both of us
Depends on what sent the bytes over UDP. UTF-8 makes the most sense here, but the bigger problem is that there is a typo in the suggestion (encode rather than decode). Simply document that anything broadcasting to EG needs to send UTF-8 encoded bytes, which will be
decoded on reception. That puts the onus on the sender to comply. Shouldn't need try-except at all, other than to log an error if the sender does not comply.
And need to do the payload as well as the event name. I covered all but when the payload length is more than 2.
http://www.eventghost.org/forum/viewtop ... 459992c984
Re: When receiving UDP with nordic characters?
Posted: Sat Nov 19, 2016 11:30 pm
by kgschlosser
thanks David for catching that dumbass messup.. LOL
happens with me all the time tho.
yeah this is for nordic characters. so it could be latin1 that's why i stated that..
but his error is for only one hex so the utf8 should work. it's when ya get 2 hex characters but the error message in the traceback doesn't show the message. and i am not sure if on a unicode error if it shows all characters out of ordinal range or just the first one it comes across.. i am thinking it's probably the first one it comes across
i am running into a similar problem with a plugin i am working on but if i encode the string with utf8 it builds the xml tree but won't convert the xml tree into a string. and if i convert it using str() i get an error elsewhere. so not exactly sure how to handle that kind of issue because i have to iterate through the whole thing..... unless maybe if i use isinstance to check and see if it's not a basestring and if not then convert it and if it's unicode then to encode it. i dunno i will have to mess with it