I’m revisiting this project and have another problem - using system.net.httpGet() from the gateway seems to have a timeout error. I have a UDT with a boolean memory tag, when that tag goes from low to high it runs a shared script that will ideally use httpGet to login to a given gateway URL and get the JSON information as discussed above. In particular, I’m trying to access the gateway the script is on, so nothing should be too odd.
def signin(urlP):
url = "http://%s:8088" % urlP
webURL = "/main/web"
username = 'admin'
password = 'password'
signinTest = shared.HTTP.checkSignin(url)
retStr = []
if signinTest == "":
retStr.append("signed in")
else:
retStr.append( "not signed in: %s" % signinTest )
retStr.append( "trying signin now" )
signinResponse = system.net.httpPost(url + webURL + signinTest, {'username': username, 'password': password})
retStr.append('Signin Response:\n%s' % signinResponse)
newTest = shared.HTTP.checkSignin(url)
if newTest == "":
retStr.append( "signin successful")
else:
retStr.append( "signin not successful")
return retStr
def checkSignin(url, ext=None):
import re
ext = ext if ext is not None else "/main/web/status/"
firstGet = system.net.httpGet(url = url + ext)
patternPre = ".*?action=\"\.(.*?)\""
pattern = re.compile(patternPre, re.DOTALL)
match = pattern.match(firstGet)
if match:
subText = match.group(1)
return str(subText)
else:
return ""
This isn’t the most optimized code, but on the ‘firstGet’ assignment in checkSignin I have a timeout error. The same code I use to call signin() works just fine when in the script console, so I think something about the gateway scope makes it different, but I’m not sure why.