# The following lines require manual changes
username = "YourUsername" # enter your username
password = "YourPassword" # enter your password
# This example establishes a https connection, but doesn't provide the server certificate validation.
# Production code should implement certificate validation.
#
import httplib
import base64
# create HTTP basic authentication string, this consists of
# "username:password" base64 encoded
auth = base64.encodestring("%s:%s"%(username,password))[:-1]
# message to send to server
message = """<sci_request version="1.0">
<send_message>
<targets>
<device id="00000000-00000000-######FF-FF######"/>
</targets>
<rci_request version="1.1">
<set_setting>
<http>
<enable>on</enable>
<port>80</port>
</http>
</set_setting>
</rci_request>
</send_message>
</sci_request>
"""
webservice = httplib.HTTPSConnection("devicecloud.digi.com")
# to what URL to send the request with a given HTTP method
webservice.putrequest("POST", "/ws/sci")
# add the authorization string into the HTTP header
webservice.putheader("Authorization", "Basic %s"%auth)
webservice.putheader("Content-type", "text/xml")
webservice.putheader("Content-length", "%d" % len(message))
webservice.putheader("Accept", "text/xml");
webservice.endheaders()
webservice.send(message)
# get the response
response = webservice.getresponse()
statuscode = response.status
statusmessage = response.reason
response_body = response.read()
# print the output to standard out
print (statuscode, statusmessage)
print response_body