ascii codec errors with device names

Posted on
Mon Oct 05, 2020 8:06 am
juntta offline
Posts: 143
Joined: Oct 13, 2014
Location: Finland

ascii codec errors with device names

Hi!

I dont know if its recommended to edit device names or not, anyway it seems to be working alright. But I ran into one issue today when I renamed one of my Apple Tv's as "AppleTV Yläkerta" and following issue raised into log:

Code: Select all
2020-10-05 16:33:17.691   ERROR          Plugin.periodCheck               in Line 5622 has error='ascii' codec can't decode byte 0xc3 in position 16: ordinal not in range(128)
looking at device:  UniFi_AppleTV_Yläkerta

Posted on
Mon Oct 05, 2020 9:19 am
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: ascii codec errors with device names

checking
the error is in
text1= dev.name.encode("utf8").ljust(30) + u" status " + status.ljust(10) +"; set to UP, reset by ping "

and I thought that is the right way to do it..

Karl

Posted on
Mon Oct 05, 2020 9:27 am
FlyingDiver offline
User avatar
Posts: 7215
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: ascii codec errors with device names

kw123 wrote:
checking
the error is in
Code: Select all
text1= dev.name.encode("utf8").ljust(30) + u" status "      + status.ljust(10) +";   set to UP,  reset by ping "

and I thought that is the right way to do it..

Karl


That last string needs to be unicode as well, since. you're concatenating them. A better way to do it is:

Code: Select all
text1 = u"{} status {};   set to UP,  reset by ping".format(dev.name.encode("utf8").ljust(30), status.ljust(10))

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Oct 05, 2020 12:26 pm
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: ascii codec errors with device names

yes. i got it

need to add the u before the " AND drop the encode("utf8")
Code: Select all
z =  u"{} status {};   bla bla  ".format(dev.name.ljust(30), status.ljust(10))

works fine

the conversion to python 3 will be "exciting"


Karl

Posted on
Mon Oct 05, 2020 1:45 pm
FlyingDiver offline
User avatar
Posts: 7215
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: ascii codec errors with device names

You can also use formatting specifiers inside the brackets to do your padding and get rid of the .ljust() calls as well.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Mon Oct 05, 2020 1:49 pm
DaveL17 offline
User avatar
Posts: 6753
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: ascii codec errors with device names

Or:

Code: Select all
u"{0:30} status {1:10};   bla bla  ".format(dev.name, status)
which works in Python 2.x and 3.x.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Mon Oct 05, 2020 2:28 pm
jay (support) offline
Site Admin
User avatar
Posts: 18219
Joined: Mar 19, 2008
Location: Austin, Texas

Re: ascii codec errors with device names

DaveL17 wrote:
Or:

Code: Select all
u"{0:30} status {1:10};   bla bla  ".format(dev.name, status)
which works in Python 2.x and 3.x.


+1 - though, rumor has it that the u"" syntax will be removed at some point. But that's in the future...

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Oct 06, 2020 2:37 am
juntta offline
Posts: 143
Joined: Oct 13, 2014
Location: Finland

Re: ascii codec errors with device names

Version 7.33.285 fixed this issue! Now devices get updated even what characters their names got!

Thanks Karl

Posted on
Tue Oct 06, 2020 9:49 am
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: ascii codec errors with device names

thanks for the feedback. it is always nice to get a positive feedback when things work .

and thanks for your patience

Karl

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 6 guests