4

A Get request is pretty easy:

def build_request(url, method='GET'):
    params = {                                            
        'oauth_version': "1.0",
        'oauth_nonce': oauth2.generate_nonce(),
        'oauth_timestamp': int(time.time())
    }
    consumer = oauth2.Consumer(key='****',secret='******')
    params['oauth_consumer_key'] = consumer.key

    req = oauth2.Request(method=method, url=url, parameters=params)
    signature_method = oauth2.SignatureMethod_HMAC_SHA1()
    req.sign_request(signature_method, consumer, None)
    return req

But now, we want to make a POST with a file. (We're using the library python-oauth2). Suggestions?

1

2 Answers 2

4

The problem is that oauth is not supposed to sign multipart/post data, but it still needs to sign the other parameters. The way I got around it was to use python-oauth2 to sign the non-file parameters and then send the request manually with urllib2.

Here's an example script. See lines 126 - 173.

Sign up to request clarification or add additional context in comments.

Comments

1

From reading the source it appears that Request takes a method to state with HTTP request to use.

Simply change your req to

req = oauth2.Request(method='POST', url=url, parameters=params)

https://github.com/simplegeo/python-oauth2/blob/master/oauth2/init.py#L342 for more info

That might go part way to solving your issue, as for the file upload you might be aable to work with supplying headers with the content see:

https://github.com/simplegeo/python-oauth2/blob/master/oauth2/init.py#L646

Apologies I have not had chance to test this yet.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.