Python sample code to read from device cloud

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:

(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
Traceback (most recent call last):
  File "", line 32, in 
  File "/usr/lib/python2.7/", line 969, in endheaders
  File "/usr/lib/python2.7/", line 829, in _send_output
  File "/usr/lib/python2.7/", line 791, in send
  File "/usr/lib/python2.7/", line 772, in connect
    self.timeout, self.source_address)
  File "/usr/lib/python2.7/", 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

When running:

# 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 = """ 

webservice = httplib.HTTP(" ", 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))
# 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?

I think you are querying for device status then it should be a GET request.
Replace POST with GET and try again.