我一直在学习如何使用开源的Eucalyptus来使用Amazon S3 API。到目前为止,我已经能够成功使用REST,但现在我也想使用SOAP。我似乎无法为我的请求生成正确的签名。该服务是给我一个403 Forbidden错误:Eucalyptus Walrus/Amazon S3 SOAP签名失败
Traceback (most recent call last):
File "soap.py", line 31, in <module>
r = w.download_file('mybucket', 'test.txt')
File "soap.py", line 27, in download_file
r = self.client.service.ListAllMyBuckets(self.access_key, timestamp, signature)
File "/usr/lib/python2.6/site-packages/suds/client.py", line 521, in __call__
return client.invoke(args, kwargs)
File "/usr/lib/python2.6/site-packages/suds/client.py", line 581, in invoke
result = self.send(soapenv)
File "/usr/lib/python2.6/site-packages/suds/client.py", line 619, in send
description=tostr(e), original_soapenv=original_soapenv)
File "/usr/lib/python2.6/site-packages/suds/client.py", line 677, in process_reply
raise Exception((status, description))
Exception: (403, u'Forbidden')
我的代码是在Python 2和使用无泡沫Jurko库发送SOAP请求:
from suds.client import Client
class WalrusSoap:
wsdl_url = 'https://s3.amazonaws.com/doc/2006-03-01/AmazonS3.wsdl'
server_url = 'https://localhost:8773/services/Walrus'
def __init__(self, access_key, secret_key):
self.access_key = access_key
self.secret_key = secret_key
self.client = Client(self.wsdl_url)
self.client.wsdl.services[0].setlocation(self.server_url)
#print self.client
def create_signature(self, operation, timestamp):
import base64, hmac, hashlib
h = hashlib.sha1(self.secret_key)
h.update("AmazonS3" + operation + timestamp)
#h = hmac.new(key=self.secret_key, msg="AmazonS3" + operation + timestamp, digestmod=hashlib.sha1)
return base64.encodestring(h.digest()).strip()
def download_file(self, bucket, filename):
from time import gmtime, strftime
timestamp = strftime('%Y-%m-%dT%H:%M:%S.001Z', gmtime())
print(timestamp)
signature = self.create_signature('ListAllMyBuckets', timestamp)
print(signature)
r = self.client.service.ListAllMyBuckets(self.access_key, timestamp, signature)
return r
w = WalrusSoap(access_key='MOBSE7FNS6OC5NYC75PG8', secret_key='yxYZmSLCg5Xw6rQVgoIuVLMAx3hZRlxDc0VOJqox')
r = w.download_file('mybucket', 'test.txt')
print(r)
我改变了服务器端点,否则WSDL指向亚马逊的常规S3服务器。我也有两种不同的方法在我的create_signature函数中创建签名。我只是简单地评论第二个,就是在彼此之间交换。两者似乎都不起作用。我的问题是我做错了什么?
SOAP验证:http://docs.aws.amazon.com/AmazonS3/latest/dev/SOAPAuthentication.html
SUDS-Jurko文档:https://bitbucket.org/jurko/suds/overview
编辑:我发现我忘了,包括的打印什么时间戳和签名用于调试目的的例子。
2014-12-05T00:27:41.001Z
0h8vxE2+k10tetXZQJxXNnNUjjw=
编辑2:另外,我知道download_file功能无法下载文件:)我仍然在测试/调试阶段
编辑3:我知道,REST是更好地使用,至少根据亚马逊的说法。 (我个人认为REST也更好。)我也已经意识到SOAP已被亚马逊弃用。然而,无论如何,我想顺着这条道路走下去,所以请帮我一个忙,不要浪费我的时间与链接到弃用。我向你保证,在编写这个SOAP代码时,我已经清楚了这个弃用。事实上,我发布的其中一个链接已在其页面顶部打印了弃用通知。但是,如果您有证据表明Walrus完全抛弃SOAP或他们停止了SOAP部分的工作,我希望看到类似的东西。但请不要告诉我亚马逊已弃用SOAP。
我知道时间不能错,因为我正在运行的连接到Walrus的脚本是从托管Walrus的虚拟机运行的。您可能已经注意到server_url指向localhost。我确实试过'localtime()'而不是'gmtime()',只是为了确定,并没有用。不幸的是,在cloud-error.log中没有任何帮助。感谢您检查我的签名。 – 2014-12-05 13:23:29
你也有证据证明Walrus不支持SOAP吗? – 2014-12-05 13:40:03