Python call to ERT Gateway returns 302 'Found' but nothing in respose_body

Newbie here attempting to read my meters via and ERT Gateway and Python script.

running ws/XbeeAttributeDataCore?condition=devConnectwareId=‘00000000-00000000-00409DFF-FF4AXXXX’ and xeProfileId = 265 and xeDeviceId=1281 and xaAttributeType=226 from the web services console return valid data.

I then export the python script and run from the command line

The following lines require manual changes

username = “xxxx” # enter your username
password = “xxxx” # enter your password

Nothing below this line should need to be changed

-------------------------------------------------

import httplib
import base64

create HTTP basic authentication string, this consists of

“username:password” base64 encoded

auth = base64.encodestring(“%s:%s”%(username,password))[:-1]
webservice = httplib.HTTP(“developer.idigi.com”,80)

to what URL to send the request with a given HTTP method

webservice.putrequest(“GET”, “ws/XbeeAttributeDataCore?condition=devConnectwareId=‘00000000-00000000-00409DFF-FF4Axxxx’ and xeProfileId = 265 and xeDeviceId=1281 and xaAttributeType=226”)

add the authorization string into the HTTP header

webservice.putheader(“Authorization”, “Basic %s”%auth)
webservice.putheader(“Content-type”, “text/xml; charset="UTF-8"”)
webservice.endheaders()

get the response

statuscode, statusmessage, header = webservice.getreply()
response_body = webservice.getfile().read()

print the output to standard out

print (statuscode, statusmessage)
print response_body

Is there something I am doing wrong?

Any help would be appreciated.

I believe there is a problem with the export when the URL contains spaces, since it doesn’t properly escape them. Try replacing each of spaces in the URL with the encoded value of %20, so:

webservice.putrequest(“GET”, “ws/XbeeAttributeDataCore?condition=devConnectwareId=‘00000000-00000000-00409DFF-FF4Axxxx’%20and%20xeProfileId%20=%20265%20and%20xeDeviceId=1281%20and%20xaAttributeType=226”)

If that works, you can look into better ways of handling the spaces if you’re interested or just stick with the hand escaping of the spaces.

Chris

Unfortunately, that did not work. Changing the spaces to %20 still returns a zero length body.

Anyone have any other thoughts?

It looks like when you exported the code a “/” was accidentally stripped out:

Try it again with: webservice.putrequest(“GET”,"/ws/XbeeAttributeData…

Chris

I able to get it work. Thanks for the help.