Trouble connecting using python 3 via the web service API

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:

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 = """ 
     
       
        
       
      
          
      
    
    
    """%(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):


500 Internal Server Error
b'			/ws/sci				500			'

I wonder what the problem here is - I basically followed the instructions in the documentation.

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.