Python requests package error, Indigo 2021.1, Big Sur

Posted on
Wed Jun 30, 2021 7:50 am
welchgregusa offline
Posts: 101
Joined: May 29, 2013
Location: Orlando, FL

Python requests package error, Indigo 2021.1, Big Sur

I have a relatively short script Python involving a "requests" package "post" sent to a local server (a pool system controller) that worked in the past in Indigo 7.5 under macOS Catalina. I recently upgraded to Indigo 2021.1, and then to macOS Big Sur.

Here is what I am issuing in the script:

import requests
requests.post('http://192.168.15.118/WNewSt.htm')


and here is the response I'm seeing:

Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Library/Application Support/Perceptive Automation/Indigo 2021.1/IndigoPluginHost.app/Contents/Resources/PlugIns/requests/api.py", line 111, in post
return request('post', url, data=data, json=json, **kwargs)
File "/Library/Application Support/Perceptive Automation/Indigo 2021.1/IndigoPluginHost.app/Contents/Resources/PlugIns/requests/api.py", line 57, in request
return session.request(method=method, url=url, **kwargs)
File "/Library/Application Support/Perceptive Automation/Indigo 2021.1/IndigoPluginHost.app/Contents/Resources/PlugIns/requests/sessions.py", line 477, in request
resp = self.send(prep, **send_kwargs)
File "/Library/Application Support/Perceptive Automation/Indigo 2021.1/IndigoPluginHost.app/Contents/Resources/PlugIns/requests/sessions.py", line 619, in send
r.content
File "/Library/Application Support/Perceptive Automation/Indigo 2021.1/IndigoPluginHost.app/Contents/Resources/PlugIns/requests/models.py", line 745, in content
self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes()
File "/Library/Application Support/Perceptive Automation/Indigo 2021.1/IndigoPluginHost.app/Contents/Resources/PlugIns/requests/models.py", line 671, in generate
raise ChunkedEncodingError(e)
ChunkedEncodingError: ("Connection broken: error(50, 'Network is down')", error(50, 'Network is down'))


Using a web browser I verified that the URL (http://192.168.15.118/WNewSt.htm) is correct and returns what I expect—a short text status string that I parse.

Anyone have any ideas for what's going on?

Thanks.

P.S. I have only limited experience w/ Python, and Python in Indigo, etc.

Posted on
Wed Jun 30, 2021 8:33 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Python requests package error, Indigo 2021.1, Big Sur

Shouldn't you be POSTing some data? This is just doing a POST with no data...

If you are just trying to receive data without sending any parameters/data, then it seems like that would be a GET.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Wed Jun 30, 2021 8:41 am
welchgregusa offline
Posts: 101
Joined: May 29, 2013
Location: Orlando, FL

Re: Python requests package error, Indigo 2021.1, Big Sur

Sorry—yes—I was trying to pare down the example to the minimum that still exhibited the error.

Here's the full initial part of the script, which (when executed) results in the same messages.

import time
import requests
import subprocess

# "press" the "ALL LIGHTS" button on the web interface (toggles)
headers = {
'Host': '192.168.15.118',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Firefox/52.0',
'Accept': '*/*',
'Accept-Language': 'en-US,en;q=0.5',
'Referer': 'http://192.168.15.118/',
'Content-Type': 'application/x-www-form-urlencoded',
'Connection': 'keep-alive',
}
data = [
('KeyId', '0A'),
('', ''),
]
response = requests.post('http://192.168.15.118/WNewSt.htm', headers=headers, data=data)


Hmmm... could the User-Agent actually matter? I assumed it did not, but I am actually running this on an M1 Mac Mini (w/ Indigo 2021.1, Big Sur).

Posted on
Wed Jun 30, 2021 9:26 am
jay (support) offline
Site Admin
User avatar
Posts: 18199
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Python requests package error, Indigo 2021.1, Big Sur

I don't think so, but it's also unlikely to be needed. In fact, I suspect the "Connection" header might be the issue. I'd just remove all the headers and see if that solves the issue since none of them are likely to be needed by the server.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Fri Jul 09, 2021 12:55 pm
welchgregusa offline
Posts: 101
Joined: May 29, 2013
Location: Orlando, FL

Re: Python requests package error, Indigo 2021.1, Big Sur

Just closing the loop on this....

In the end I think the error is because the return data (from the post) is more than usual (long story), and seemingly irrelevant. The key press (in "data") is working, so I just trapped the error (using a try) and ignored it. Not as satisfying as truly fixing it, but I have to move on.

Thanks Jay.

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests