Created
October 10, 2012 05:37
-
-
Save mikelopez/3863359 to your computer and use it in GitHub Desktop.
Generate a signature for a request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def do_signature(self, secret_key): | |
keys = sorted(self.params.keys()) | |
args = '&'.join('%s=%s' % (key, quote(unicode(self.params[key]).encode('utf-8'),safe='~')) for key in keys) | |
msg = 'GET' | |
msg += '\necs.amazonaws.com' | |
msg += '\n/onca/xml' | |
msg += '\n' + args | |
signature = base64.encodestring(hmac.new(self.secret_key, msg, hashlib.sha256).digest()) | |
url = 'http://%s/onca/xml?%s&Signature=%s' % ('ecs.amazonaws.com', args, signature.replace('/','%2F').replace('+','%2B').replace('=','%3D')) | |
return url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment