Strange IO error from httpPut

Hi, All

I face a strange issue when I try to use system.net.httpPut, I use exactly same code in script console, it runs well, no any issue, but when I put it into tag value changed event, it will return IO error

the code is like this:

from urllib2 import URLError, HTTPError
apiKey = 'xxxx-xxxxx-xx'
Type = 'application/json'
header = {
		'appKey': '%s' %apiKey
		}
data = '{"Partnumber":"TestPart_N1"}'
fullurl = 'http://myaddress:8080/Properties/Partnumber'
try:
	updateValue = system.net.httpPut(fullurl,Type,data,60000,60000,'','',header)
	response = {'success':True,'response':updateValue.encode('utf-8')}
except HTTPError, he:
	response = {'success':False,'HTTPError':he, 'url':fullurl, 'putData':data}
except URLError, ue:
	response = {'success':False,'URLError':ue, 'url':fullurl, 'putData':data}
except IOError, ioe:
	response = {'success':False,'IOError':ioe, 'url':fullurl, 'putData':data}
except:
	response = {'success':False,'otherException':'Timeout', 'url':fullurl, 'putData':data}
print (str(response))

when I run it in the script console, it returns: {‘success’: True, ‘response’: ‘’}

but when I try it in the tag value changed event, it returns:
{‘url’: u’http://myaddress:8080/Properties/Partnumber’, ‘IOError’: IOError(‘Server returned HTTP response code: 503 for URL: http://www.myaddress.com/Properties/Partnumber’,), ‘success’: False, ‘putData’: ‘{“Partnumber”:“TestPart_N1”}’}

the strange thing is here, in the fullurl, I try to connect to http://myaddress:8080, but in the IO error message, it shows code 503 and URL changed to http://www.myaddress.com, which is not I want to connect to, any idea about this?

thanks in advance

I’ve seen this type of behavior in browsers before when a given name doesn’t resolve (it will try prefixing with “www.”). Are you running the Designer on the same machine as the gateway? Assuming that is the case, the name resolution will be different when run in a [gateway] tag script. I’d check to see if myaddress is able to resolve on the gateway machine (via nslookup myaddress).

Thanks @kcollins1, I tried both, our gateway running on a dedicated server, I have tried running designer on my laptop and server both side, same result, and from gateway server, nslookup and browser both can return the correct response, so that’s the strange point

You might try the equivalent implementation with system.net.httpClient and see if you get any difference in behavior.

have tried httpClient, not same result, but similar, I use it like this:

Client = system.net.httpClient()
response = Client.put(url=fullurl,data=data, headers=header)

from script console, I got statusCode 200, in tag event, I got statusCode 307, if I add redirect_policy then the code will be 503

so really don’t know what happens here, only can working is call httplib and use request feature

Tip: There’s a </> code formatting button on the editor toolbar. Select your code and click the button and it will format properly with indents. There’s a 'pencil` edit button below your post. I recommend that you capitalise and punctuate your posts properly for legibility and to avoid detracting from the content. Your compiler wouldn’t let you away with it!