通过传递URL作为参数进行CloudStack API调用时出现签名错误

2024-06-13 07:02:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我想要像here中描述的那样进行cloudstackapi调用'uploadVolume'。在

我正在使用python,我的代码适用于所有其他API调用,uploadVolume除外。在

secretkey = 'EdKz8Po3zmFWacumfxirauUBPVcLEWKq0qRox1iqhzAsrmLnJaEJxL2IsyDfyPE2Oh5AODJG3ZGKZf6A08xQAw'
apikey = 'YIShhcJ1PaGF5awJlci46qyAqhEN8WYdtUodHAT2wp7-zpN21_fJpcy1POTiMXOlFH-f-rO3zAs3tYRGcFqxwg'

request['command']='uploadVolume'
request['format']='QCOW2'
request['name']='test'
request['url']='http://192.168.122.100/image.qcow2'
request['zoneid']='959416fc-71f0-461c-99f0-28449e098036'
request['response']='json'
request['apikey']= apikey

baseurl='http://192.168.122.250:8080/client/api?'

request_str='&'.join(['='.join([k,urllib.quote_plus(request[k])]) for k in request.keys()])
sig_str='&'.join(['='.join([k.lower(),urllib.quote_plus(request[k].lower().replace('+','%20'))])for k in sorted(request.iterkeys())])
sig=urllib.quote_plus(base64.encodestring(hmac.new(secretkey,sig_str,hashlib.sha1).digest()).strip())

url=baseurl+request_str+'&signature='+sig

生成的URL如下所示:

^{pr2}$

响应表明存在签名问题:

^{3}$

经过一些测试,我发现签名错误是由url参数引起的。如果我用这个参数中的任何字符串替换url,那么签名是正确的,但是(显然)命令失败(因为CloudStack找不到图像)。在

但我不确定网址的特殊性。在

有人知道怎么解决这个问题吗?在


Tags: inhttpurlforrequestplusurllibquote