Home/Support/Support Forum/Trouble connecting using python 3 via the web service API
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

Trouble connecting using python 3 via the web service API

0 votes
I am trying to connect do a device cloud service using python3. I ported the script that can be found here: http://ftp1.digi.com/support/documentation/html/90002008/90002008_M/index.htm#Programming Topics/Writing Web Services Client Applications.htm to python 3:
Code:
import http.client import base64 if __name__ == '__main__': # The following lines require manual changes username = "xxxx" # enter your username password = "xxxx" # enter your password #device_id = "00000000-00000000-00409DFF-FF7660EC" # enter device id of target device_id = "00000000-00000000-00409DFF-FF49B098" # Nothing below this line should need to be changed # ------------------------------------------------- # create HTTP basic authentication string, this consists of encodestring = '%s:%s' % (username, password) auth = base64.encodebytes(encodestring.encode('utf-8'))[:-1] # message to send to server message = """<sci_request version="1.0"> <send_message> <targets> <device id="%s"/> </targets> <rci_request version="1.1"> <query_state/> </rci_request> </send_message> </sci_request> """%(device_id) webservice = http.client.HTTPConnection("login.etherios.com", 80) # 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; charset=\"UTF-8\"") webservice.putheader("Content-length", "%d" % len(message)) webservice.endheaders() webservice.send(message.encode('utf-8')) # get the response response = webservice.getresponse() print(response.status, response.reason) response_body = response.read() print (response_body)
It generally works, but I get the following error (that does not give me much information):
Code:
500 Internal Server Error b'<wsError>\t<request>\t\t<path>/ws/sci</path>\t</request>\t<error>\t\t<code>500</code>\t\t<message></message>\t</error></wsError>'
I wonder what the problem here is - I basically followed the instructions in the documentation.
asked Oct 16, 2013 in Python by markus.mueller New to the Community (0 points)
edited Oct 16, 2013 by markus.mueller

Please log in or register to answer this question.

1 Answer

0 votes
Login to Device Cloud of Digi, go to Documenation-->API Explorer, select the request, go to Export and select python, you will get the python program, try the program.
answered Oct 26, 2013 by 16ksa23 Veteran of the Digi Community (426 points)
...