Script error but no idea what script

Posted on
Tue Aug 23, 2022 9:24 am
Different Computers offline
User avatar
Posts: 2557
Joined: Jan 02, 2016
Location: East Coast

Script error but no idea what script

Just upgraded from 2021 to 2022.1 and now I see this in the log regularly:
Code: Select all
 Script Error                    schedule "Log Output" embedded script error:
   Script Error                    'ascii' codec can't decode byte 0xc2 in position 551: ordinal not in range(128)
   Script Error                    Exception Traceback (most recent call shown last):

     embedded script, line 16, at top level
     embedded script, line 7, in tail
     File '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/encodings/ascii.py', line 26, in decode
       return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 551: ordinal not in range(128)


But there's no reference to tell me which script this might be happening in. Any easy way to zero in on this a bit more? I don't have that many embedded scripts.

Also, odds are I won't have the slightest idea how to fix this, so if the error gives any of you pythonistas an idea of how to proceed once I find the script, I'd appreciate it!

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Tue Aug 23, 2022 9:27 am
Different Computers offline
User avatar
Posts: 2557
Joined: Jan 02, 2016
Location: East Coast

Re: Script error but no idea what script

Oh wait... something with the schedule "log output". Duh..... let's see.

Code: Select all
import sys
import collections
import re

def tail(iterable, N):
    deq = collections.deque()
    for thing in iterable:
        if len(deq) >= N:
            deq.popleft()
        deq.append(thing)
    return list(deq)

# A list of the variable IDs - this script doesn't create them so they have to exist already
variable_ids = [69497648, 1214336659, 1247906225]

lines = tail(open("/Library/Application Support/Perceptive Automation/Indigo 7.5/Logs/indigo_log.txt"), len(variable_ids))
for index, line in enumerate(lines):
    # if the line starts with the date/time string formatted like this: 2018-02-01 00:00:24.350
    if re.match(r'^[0-9]{4}\-[0-9]{2}\-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}', line):
        # remove everything from the start of the line through the first tab, which removes the date
        line = "\t".join(line.split("\t")[1:])
    indigo.variable.updateValue(variable_ids[index], value=line)


This was someone else's very helpful script, that I'm pretty sure I copied verbatim.... years ago. Looks like there's def a problem with the "Indigo 7.5/Logs/" part. That's easy.

EDIT: "Easy" :/

Still getting
Code: Select all
Script Error                    embedded script error:
   Script Error                    'ascii' codec can't decode byte 0xe2 in position 1279: ordinal not in range(128)
   Script Error                    Exception Traceback (most recent call shown last):

     embedded script, line 16, at top level
     embedded script, line 7, in tail
     File '/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/encodings/ascii.py', line 26, in decode
       return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 1279: ordinal not in range(128)

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Tue Aug 23, 2022 10:58 am
matt (support) offline
Site Admin
User avatar
Posts: 21418
Joined: Jan 27, 2003
Location: Texas

Re: Script error but no idea what script

Try adding encoding="utf-8" as an argument to the open() call:

Code: Select all
lines = tail(open(encoding="utf-8", "/Library/Application Support/Perceptive Automation/Indigo 2022.1/Logs/indigo_log.txt"), len(variable_ids))

Image

Posted on
Tue Aug 23, 2022 11:13 am
Different Computers offline
User avatar
Posts: 2557
Joined: Jan 02, 2016
Location: East Coast

Re: Script error but no idea what script

When I copy that verbatim, on compile I get the error "positional argument follows keyword argument"

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Tue Aug 23, 2022 5:38 pm
matt (support) offline
Site Admin
User avatar
Posts: 21418
Joined: Jan 27, 2003
Location: Texas

Re: Script error but no idea what script

Move the argument I added to be after the file path argument.

Image

Posted on
Wed Aug 24, 2022 8:16 am
Different Computers offline
User avatar
Posts: 2557
Joined: Jan 02, 2016
Location: East Coast

Re: Script error but no idea what script

Sorry about this. I confess I've forgotten 80% of the python I ever knew, and I only knew about 2% of python in the first place.

I'm probably putting the UTF bit in the wrong place:

https://imgur.com/tmfqVAh

But here's another related script that might be giving a hint about the original problem, as it highlights something else entirely:

https://imgur.com/NEUKBqw

(Also tried posting these as images, but got "not possible to determine the dimensions of the image.)

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Wed Aug 24, 2022 9:01 am
jay (support) offline
Site Admin
User avatar
Posts: 18230
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Script error but no idea what script

Please copy/paste actual script text into your posts and surround them with code tags (see the Code button above the editor when editing a message). That way, we can correct the script without having to type it all in again. Yes, you have the encoding in the wrong function call - it's in the tail() call now, it should be in the open() call, right after the path to the file before the closing parenthesis.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Aug 24, 2022 10:12 am
Different Computers offline
User avatar
Posts: 2557
Joined: Jan 02, 2016
Location: East Coast

Re: Script error but no idea what script

Sorry, thought the highlighting and error message would be helpful. Whoops!

Code: Select all
import sys
import collections
import re

def tail(iterable, N):
    deq = collections.deque()
    for thing in iterable:
        if len(deq) >= N:
            deq.popleft()
        deq.append(thing)
    return list(deq)

# A list of the variable IDs - this script doesn't create them so they have to exist already
variable_ids = [69497648, 1214336659, 1247906225]

lines = tail(open("/Library/Application Support/Perceptive Automation/Indigo 2022.1/Logs/indigo_log.txt", encoding="utf-8"), len(variable_ids))
for index, line in enumerate(lines):
    # if the line starts with the date/time string formatted like this: 2018-02-01 00:00:24.350
    if re.match(r'^[0-9]{4}\-[0-9]{2}\-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{3}', line):
        # remove everything from the start of the line through the first tab, which removes the date
        line = "\t".join(line.split("\t")[1:])
    indigo.variable.updateValue(variable_ids[index], value=line)


This compiles but now returns
Code: Select all
Script Error                    invalid syntax. Perhaps you forgot a comma?
   Script Error                    around line 16 - "lines = tail(open("/Library/Application Support/Perceptive Automation/Indigo 2022.1/Logs/indigo_log.txt" encoding="utf-8"), len(variable_ids))"

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Posted on
Wed Aug 24, 2022 10:19 am
Different Computers offline
User avatar
Posts: 2557
Joined: Jan 02, 2016
Location: East Coast

Re: Script error but no idea what script

hmmm, I think I fiddled until the error stopped. Think I had an extra space in there somewhere.

The other error was also the same problem, and is fixed now.

Thanks!

SmartThings refugee, so happy to be on Indigo. Monterey on a base M1 Mini w/Harmony Hub, Hue, DomoPad, Dynamic URL, Device Extensions, HomeKitLink, Grafana, Plex, uniFAP, Fantastic Weather, Nanoleaf, LED Simple Effects, Bond Home, Camect.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 5 guests