Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use with requests.post? #19

Open
jonhandlermac opened this issue Aug 26, 2016 · 2 comments
Open

How to use with requests.post? #19

jonhandlermac opened this issue Aug 26, 2016 · 2 comments

Comments

@jonhandlermac
Copy link

I may be brain dead, or just new at this, but how do you send a signed POST request?

Trying this:

class CredentialsProvider(object):

def __init__(self):
    self.creds = None
    self.sts = sts = boto3.client('sts')
    self.tz = get_localzone()
    self.session_num = 1

def auth(self):
    if not self.creds or datetime.now(self.tz) > self.creds['Expiration']:
        session_name = "sesh%d" % self.session_num
        self.session_num += 1
        self.creds = self.sts.assume_role(RoleArn='arn:aws:iam::XXXX:role/YYYYY', 
                                     RoleSessionName=session_name)['Credentials']
        self.auth = AWS4Auth(self.creds['AccessKeyId'],
                             self.creds['SecretAccessKey'],
                             'us-west-2', 'es',
                             session_token=self.creds['SessionToken'])
    return self.auth

...

    try:
        r = requests.post(url, data=json.JSONEncoder().encode(jsondata), auth=self.credentials_provider.auth())
    except Exception as e:
        print "HTTP exception for POST %s" % e

...

HTTP exception for POST call() takes exactly 2 arguments (1 given)

Works for get requests from the same host (python interactive) with
requests.get(endpoint, auth=awsauth)

I can't find any documentation on this either in the requests library or here.

@Tethik
Copy link

Tethik commented Apr 26, 2018

I'm also having issues trying to use this library with POST-requests. GET-requests work fine. It looks to me like the signatures might not be working properly for POST-requests, maybe because the payload is not signed? I get the following error.

{'message': 'The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.'}

Readme does say: GET URL parameter and POST parameter authentication are not supported..

@kjpgit
Copy link

kjpgit commented Apr 2, 2019

For some reason, requests.put() works for me if using json=, but not data=.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants