Skip to content

Instantly share code, notes, and snippets.

@mikelopez
Created October 10, 2012 05:37
Show Gist options
  • Save mikelopez/3863359 to your computer and use it in GitHub Desktop.
Save mikelopez/3863359 to your computer and use it in GitHub Desktop.
Generate a signature for a request
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