Home/Support/Support Forum/Python sample code to read from device cloud
Welcome to Digi Forum, where you can ask questions and receive answers from other members of the community.

Python sample code to read from device cloud

0 votes
I am trying to run the sample code in the "writing web services client applications" section.

I do just run this as regular python code no?

I get an error:
Code:
(gedit:4352): Gtk-WARNING **: Calling Inhibit failed: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager was not provided by any .service files michael@michael-G41MT-ES2L:~/workspace/device$ sudo python test.py Traceback (most recent call last): File "test.py", line 32, in <module> webservice.endheaders() File "/usr/lib/python2.7/httplib.py", line 969, in endheaders self._send_output(message_body) File "/usr/lib/python2.7/httplib.py", line 829, in _send_output self.send(msg) File "/usr/lib/python2.7/httplib.py", line 791, in send self.connect() File "/usr/lib/python2.7/httplib.py", line 772, in connect self.timeout, self.source_address) File "/usr/lib/python2.7/socket.py", line 553, in create_connection for res in getaddrinfo(host, port, 0, SOCK_STREAM): socket.gaierror: [Errno -2] Name or service not known michael@michael-G41MT-ES2L:~/workspace/device$ sudo gedit test.py

When running:
Code:
# The following lines require manual changes username = "mickpc00" # enter your username password = "#######" # enter your password device_id = "000000000000000000409DFFFF5E015C" # enter device id of target # 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] # 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 = httplib.HTTP("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) # 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

Any ideas on the problem?
asked Aug 31, 2014 in Python by mickpc00 New to the Community (1 point)

Please log in or register to answer this question.

1 Answer

0 votes
I think you are querying for device status then it should be a GET request.
Replace POST with GET and try again.
answered Aug 31, 2014 by 16ksa23 Veteran of the Digi Community (426 points)
...