UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2

Posted on
Thu Apr 19, 2018 11:36 am
Jann offline
Posts: 120
Joined: Mar 12, 2006
Location: Auburndale, FL

Re: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2

I have a many Hue device types (i think 5 or 6...)

I'll change them all...

Posted on
Thu Apr 19, 2018 11:52 am
Jann offline
Posts: 120
Joined: Mar 12, 2006
Location: Auburndale, FL

Re: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2

Well, SHOOT!

It didn't work. Indigo still complaining. This one is different tho...

I changed the name of the Hue device to have the smart apostrophe, made the changes to all the debug lines in the python script, rebooted the server (for good measure) Then - for funsies - I just went to that device in indigo and hit "Send Status Request," the following happened:

Code: Select all
 Hue Lights Error                Error in plugin execution ExecuteAction:

Traceback (most recent call last):
  File "plugin.py", line 3443, in actionControlDimmerRelay
  File "plugin.py", line 4784, in getBulbStatus
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 176: ordinal not in range(128)



Line 4784 is one of the 8 or so lines I changed to:

Code: Select all
self.debugLog(u"Data from hub: {}".format(r.content))


Are we sure that's the line to use?
(ps: it STILL has the same problem assigning a NEW indigo device to a Hue device with an apostrophe.)

Posted on
Thu Apr 19, 2018 11:54 am
FlyingDiver offline
User avatar
Posts: 7190
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2

Since those are just debug logging lines, you could just comment them out and see if it works.

Code: Select all
# self.debugLog(u"Data from hub: {}".format(r.content))

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

Posted on
Thu Apr 19, 2018 11:57 am
Colorado4Wheeler offline
User avatar
Posts: 2794
Joined: Jul 20, 2009
Location: Colorado

Re: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2

You could try opening it up in TextWrangler and doing a replace all:

Code: Select all
replace self.debugLog with # self.debugLog

My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here

Posted on
Thu Apr 19, 2018 11:58 am
Jann offline
Posts: 120
Joined: Mar 12, 2006
Location: Auburndale, FL

Re: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2

Duh! (that "Duh" was for ME not YOU! Sorry....)

I'm a programmer and didn't think of this. I am just not a PYTHON programmer. BTW: what is the best way to restart after changing the python plugin? I rebooted the mini to make sure but Plug ins->Hue Lights->reload didn't seem to load the newly changed python script?

Thanks for ALL your help!

Jann

Posted on
Thu Apr 19, 2018 12:01 pm
FlyingDiver offline
User avatar
Posts: 7190
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2

Jann wrote:
I'm a programmer and didn't think of this. I am just not a PYTHON programmer. BTW: what is the best way to restart after changing the python plugin? I rebooted the mini to make sure but Plug ins->Hue Lights->reload didn't seem to load the newly changed python script?


It should, if you're actually editing the correct files. That's what I do 99% of the time while working on a plugin. Just do a restart on the plugin.

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

Posted on
Thu Apr 19, 2018 12:09 pm
Jann offline
Posts: 120
Joined: Mar 12, 2006
Location: Auburndale, FL

Re: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2

FINALLY!

The "commenting out" worked...

As did the "reload" of the plug-in. I just hadn't waited for the important thing upon reload...the plugin stops, starts and UNTIL it gets the JSON from the hue hub it doesn't get the "changed" name of the hue light... so I was trying to do things too fast.

Oh, well. I hope this gets fixed in the regular release...cos commenting out debug lines isn't the best fix.

Thanks for all the help!

Jann

Posted on
Thu Apr 19, 2018 2:22 pm
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

Re: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2

In order for me to fix the debug lines, I need to be able to test this error condition, so it’d be gelpful to see the actual data coming from the Hue hub. Hard to get that if the debug lines are commented out though. Haha.

Posted on
Thu Apr 19, 2018 2:56 pm
FlyingDiver offline
User avatar
Posts: 7190
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2

nsheldon wrote:
In order for me to fix the debug lines, I need to be able to test this error condition, so it’d be gelpful to see the actual data coming from the Hue hub. Hard to get that if the debug lines are commented out though. Haha.


Can you rename one of your devices with a unicode character in it? And maybe try some variants on the string conversion, like using:

Code: Select all
print(u"Something interesting: {0}".format(some_var.decode('utf-8')))

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

Posted on
Thu Apr 19, 2018 3:09 pm
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

Re: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2

Yea. I’ll try that. That should be a good enough test. It’ll probably take me a bit to get a fix out.

Posted on
Thu Apr 19, 2018 3:12 pm
FlyingDiver offline
User avatar
Posts: 7190
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2

I would also recommend doing the debug statement on the resulting JSON data, not the raw data from the request. That would probably eliminate the error totally, as the JSON conversion should correctly identify the strings as unicode.

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

Posted on
Thu Apr 19, 2018 3:51 pm
nsheldon offline
Posts: 2469
Joined: Aug 09, 2010
Location: CA

Re: UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2

Thanks for the recommendation.

Who is online

Users browsing this forum: No registered users and 1 guest