python - API Query results error "The request signature we calculated does not match the signature you provided" -


i doing ec2 api query , facing error "the request signature calculated not match signature provided."

the fact have taken care of in ec2 documentation (signatureversion 2) still facing error , cant figure out problem.

here details:

1) signin string:

s="""get\n ec2.amazonaws.com\n /\n    awsaccesskeyid=access_id&action=describesecuritygroups&signaturemethod=hmacsha256    &signatureversion=2&timestamp=2013-10-06t14%3a15%3a30&version=2013-08-15""" 

2) python code generate signature:

#!/bin/env python2.7  import hmac import hashlib import base64  s="""get\n ec2.amazonaws.com\n /\n awsaccesskeyid=acces_id&action=describesecuritygroups& signaturemethod=hmacsha256&signatureversion=2&timestamp=2013-10-   06t14%3a15%3a30&version=2013-08-15"""  signature=base64.b64encode(hmac.new("secret_key_id", msg=s,   digestmod=hashlib.sha256).digest()) print(signature) 

3) browser request:

https://ec2.amazonaws.com/?awsaccesskeyid=access_id&action=describesecuritygroups&signaturemethod=hmacsha256&signatureversion=2&timestamp=2013-10-06t14%3a15%3a30&version=2013-08-15&signature=cccccccccccccccccc

thanks

you need url encode base-64 string:

>>> import urllib >>> urllib.quote('4kvpv1bhgaayng4u6ofiqh6u5ici8wijy+ybzddki0c=') '4kvpv1bhgaayng4u6ofiqh6u5ici8wijy%2bybzddki0c%3d' 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -