Script error: the server has closed the connection

Posted on
Thu Mar 18, 2021 12:40 pm
gadgetnut offline
User avatar
Posts: 125
Joined: Nov 03, 2005
Location: San Juan Islands

Script error: the server has closed the connection

Hello, All, running Indigo 7.5 on a Mac Mini running macOS 11.2.3, a few years ago a friend wrote a short script that we fire off with scheduled events to individually control motorized shades in seven rooms. Everything has worked quite well for the last 3+ years. We recently started getting two new errors in the Indigo logs.

After a restart of Mac Mini we can sometimes execute a script and the shades will move. But after a couple deployments this error consistently comes up:

Schedule
Action Group
Script Error

Shades Bedroom 2 Winter Close
Shades Bedroom2 Close
embedded script: No status line
received - the server has closed the connection
Script Error Exception Traceback (most recent
call shown last):
embedded script, line 10, at top level
File "/System/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/urllib2.py", line 429, in open
response = self._open(req, data)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/urllib2.py", line 447, in _open
'_open', req)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/urllib2.py", line 407, in _call_chain
result = func(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/urllib2.py", line 1228, in http_open
return self.do_open(httplib.HTTPConnection, req)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/urllib2.py", line 1201, in do_open
r = h.getresponse(buffering=True)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/httplib.py", line 1134, in getresponse
response.begin()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/httplib.py", line 442, in begin
version, status, reason = self._read_status()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/httplib.py", line 406, in _read_status
raise BadStatusLine("No status line received - the server has
closed the connection")
BadStatusLine: No status line received - the server has closed the
connection



The second error regularly appears at random times:

Error reflector connection test failed: timed out

Can someone help interpret what might be going on?

Thanks very much in advance.

Posted on
Thu Mar 18, 2021 1:18 pm
FlyingDiver offline
User avatar
Posts: 5335
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Script error: the server has closed the connection

You're going to need to post the actual script. And please use the CODE tags.

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

Posted on
Thu Mar 18, 2021 2:05 pm
gadgetnut offline
User avatar
Posts: 125
Joined: Nov 03, 2005
Location: San Juan Islands

Re: Script error: the server has closed the connection

Very good, Joe.. Thank you for the tip about the code tag, too.

This is the Bedroom 2 Close script. I removed the credentials.

Code: Select all
# indigo.server.log(the_page)

import urllib2, base64

request = urllib2.Request("http://192.168.1.73/set.cgi?addr=6&cmd=gset&pos=255&num=&timestamp=1465601351800")
username="xxxxxx"
password="xxxxxx"
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)   
result = urllib2.urlopen(request)

Posted on
Thu Mar 18, 2021 2:10 pm
FlyingDiver offline
User avatar
Posts: 5335
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Script error: the server has closed the connection

Try this, with username and password.

Code: Select all
import requests
result = requests.get("http://192.168.1.73/set.cgi?addr=6&cmd=gset&pos=255&num=&timestamp=1465601351800",  auth=('username', 'password'))

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

Posted on
Thu Mar 18, 2021 2:27 pm
gadgetnut offline
User avatar
Posts: 125
Joined: Nov 03, 2005
Location: San Juan Islands

Re: Script error: the server has closed the connection

Thanks, Joe, I am logged into the Indigo installation remotely...

Please tell me the entire contents that should appear in the Indigo Embedded Python window? If I Select All and copy and paste from your post above, and correct the user and password credentials, is that the entirety that needs to be in that window?

Posted on
Thu Mar 18, 2021 2:30 pm
FlyingDiver offline
User avatar
Posts: 5335
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Script error: the server has closed the connection

Yes, that is the entirety of the script. 2 lines. You could assign username and password to variables as your original script does, if you want. Which would make it four lines.

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

Posted on
Thu Mar 18, 2021 2:37 pm
gadgetnut offline
User avatar
Posts: 125
Joined: Nov 03, 2005
Location: San Juan Islands

Re: Script error: the server has closed the connection

I'm sorry I don't understand, could you please restate regarding how I should re-enter the proper credentials into the script and the entire contents of the embedded Python window? Thank you.

Posted on
Thu Mar 18, 2021 2:39 pm
FlyingDiver offline
User avatar
Posts: 5335
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Script error: the server has closed the connection

gadgetnut wrote:
I'm sorry I don't understand, could you please restate regarding how I should re-enter the proper credentials into the script and the entire contents of the embedded Python window? Thank you.


In the two line script, change the quoted 'username' and 'password' to the actual username and password (still in quotes).

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

Posted on
Thu Mar 18, 2021 2:51 pm
gadgetnut offline
User avatar
Posts: 125
Joined: Nov 03, 2005
Location: San Juan Islands

Re: Script error: the server has closed the connection

Yay, Joe, that did work exactly.

As we deliberate if it is our Python scripts that need a structural revision, I wanted you to know that when I first remote logged into this Mac Mini to try your script, Safari or Chrome could not load the webpage on the LAN for the Somfy web server, 192.168.1.73. I tried to load the router at 192.168.1.1 and that wouldn't load either. We restarted the Mac Mini, then the Somfy webpage did load and your revised script did work.

I'm wondering if something is going on in the local network, because we seem to have Indigo Shade Control with the existing scripts for a few minutes then the errors start. We restart the Mac Mini and it works again for a little while.

Note we also have a persistent Indigo Error reflector connection test failed: timed out... that could be the Mac Mini having network problems, couldn't it?

Posted on
Thu Mar 18, 2021 3:11 pm
FlyingDiver offline
User avatar
Posts: 5335
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Script error: the server has closed the connection

Yeah, that does sound like an issue with multiple network connections from the mini. Hard to tell what's causing it.

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

Posted on
Thu Mar 18, 2021 3:20 pm
gadgetnut offline
User avatar
Posts: 125
Joined: Nov 03, 2005
Location: San Juan Islands

Re: Script error: the server has closed the connection

Understood. Prior to this current error, the existing scripts had been working fairly well for us. Just up this thread you revised our existing script with something quite a bit shorter.

Would you suggest there's anything in our current Python structure we should improve or change? If your script is more effective, could you tell me generically what needs to be changed so that I could apply that same change to the other 17 scripts we rely on?

Posted on
Thu Mar 18, 2021 3:37 pm
FlyingDiver offline
User avatar
Posts: 5335
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Script error: the server has closed the connection

Using the requests library is simpler and more robust than using urllib directly. It knows how to do Basic Auth natively, so you don't need the extra steps to create the auth header. So for all your other scripts, you could just use the one I posted and change the embedded URL for the specific shade.

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

Posted on
Thu Mar 18, 2021 3:44 pm
gadgetnut offline
User avatar
Posts: 125
Joined: Nov 03, 2005
Location: San Juan Islands

Re: Script error: the server has closed the connection

Understood. That's what I will do. Thank you very much for jumping to help me today. In the good old days, I would invite you to lunch!

As we debug this current challenge, I will followup here again briefly with the resolution and whether a network snafu is also a culprit, especially considering the reflector connection fail error.

Posted on
Fri Mar 19, 2021 1:35 pm
gadgetnut offline
User avatar
Posts: 125
Joined: Nov 03, 2005
Location: San Juan Islands

Re: Script error: the server has closed the connection

Hi, again, FlyingDiver. I wanted to provide greater detail on our results after running the script revision you provided.

On executing your new script we received the same error as when attempting to execute our previous script.

On restart of the Mac Mini, your new script worked perfectly. Many hours later, this morning, a regularly scheduled event triggered an old script and the error presented itself.

At this point I would not expect either version to work again until I restart the Mac Mini. Not sure if our old script structure could be causing this problem? I can disable all the old events and try to fire only the new scripts and see if that makes a difference. If that works, I could update the other 20 or so we rely on.

I'm working two angles here, as we're also experiencing a recurrent Reflector error (discussed here.) I suspect a network problem is creeping in. If the Mac Mini becomes unable to find the Autelis Somfy web server on the LAN to which the script refers- that could cause this error, couldn't it?

Posted on
Fri Mar 19, 2021 1:38 pm
FlyingDiver offline
User avatar
Posts: 5335
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: Script error: the server has closed the connection

Yes, a LAN problem could cause both issues.

The new and old scripts do pretty much the same thing, just using different HTTP libraries. I'd be curious to know if a curl command in Terminal gives the same error.

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

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests