Getting a recently modified file list from the Device Cloud

This doesnt work on the WR21 or my native python environment on my PC using this exact file with my login credentials. This is using code from the Etherios API Explorer and Documentation. I am able to get directory listings and actual files just fine. The same call in the browser also works as expected, but not in the Python environment.


# The following lines require manual changes 
username = ''# enter your username
password = '' # enter your password 
# 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]
webservice = httplib.HTTP("login.etherios.com",80)
 
# to what URL to send the request with a given HTTP method
 
webservice.putrequest("GET", "/ws/FileData?condition=fdType='file' and fdLastModifiedDate>'2013-12-06T10:50:00.000Z'") #505 Version not supported error
#   "http://login.etherios.com/ws/FileData?condition=fdType='file' and fdLastModifiedDate>'2013-12-06T10:50:00.000Z'" #works in browser...
# add the authorization string into the HTTP header
webservice.putheader("Authorization", "Basic %s"%auth)
webservice.putheader("Content-type", "text/xml; charset=\"UTF-8\"")
webservice.endheaders()
 
# 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

[http://ftp1.digi.com/support/documentation/html/90002008/90002008_N/index.htm#Programming Topics/Resources.htm#FileData%3FTocPath%3DDevice%20Cloud%20Programming%20Guide%7CResources%7C_____6](http://ftp1.digi.com/support/documentation/html/90002008/90002008_N/index.htm#Programming Topics/Resources.htm#FileData%3FTocPath%3DDevice%20Cloud%20Programming%20Guide%7CResources%7C_____6)

Hi,

The problem is likely that the spaces in the URL are not appropriately URL encoded. If you change the spaces to %20 it should work:

webservice.putrequest(β€œGET”, β€œ/ws/FileData?condition=fdType=β€˜file’%20and%20fdLastModifiedDate>β€˜2013-12-06T10:50:00.000Z’”) #505 Version not supported error

Your browser automatically URL encodes the spaces which is why it works there and not from the script.

1 Like