I'm a complete beginner learning Python. I'm writing code to get response of cloudstack api call 'listTemplates'. But what ever i did, it shows a error message like 'Unable to execute API command listtemplates due to missing parameter templatefilter'
i have tried to specify thar parameter but failed. can anyone show how to write the code to specify the parameter 'templatefilter' in this code
import getopt
import sys
import hmac
import hashlib
import base64
import urllib
def formattedCmd(api, cmd):
s = 'apiKey=' + api + '&' + cmd
return s
def encypt(string, key):
h = hmac.new(key, string, hashlib.sha1)
# print '\n' + h.digest()
return base64.b64encode(h.digest())
def formattedUrl(baseUrl, api, cmd, signature):
url = baseUrl + '?' + formattedCmd(api, cmd) + '&' + urllib.urlencode({'signature': signature})
return url
def main():
print 'ffffffffffffffffffffffffff'
try:
print getopt.getopt(sys.argv[1:], 'u:a:s:', ['help', 'output='])
opts, args = getopt.getopt(sys.argv[1:], 'u:a:s:', ['help', 'output='])
print opts, args,'print'
except getopt.GetoptError, err:
print str(err)
sys.exit(2)
baseUrl = 'http://10.176.14.26:8080/client/api'
cmd = 'command=listTemplates'
temf= 'templatefilter=featured'
api = 'Qo9Qwfatwz9ARB328Btn9PftzL2Cf5LOWd8OFyJmiM513tpTIm-zKxJoWkWqf353Df397xcLdKXGk8_JO8nM3Q'
secret = '-kgkBuBUrGFeIC4gUvngSK_3Ypmi7fuF8XdVXIusnyyiEP2YUcG3FnPUGJGy3rp3Bw5ZNnqgS-9tIfyV1QnK1g'
for o, a in opts:
if o == '-u':
cmd = a
elif o == '-a':
api = a
elif o == '-s':
secret = a
else:
assert False, 'unhandled option'
newCmd = formattedCmd(api, cmd).lower()
signature = encypt(newCmd, secret)
url = formattedUrl(baseUrl, api, cmd, signature)
print '\n' + url
if __name__ == '__main__':
main()