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

Using only consumer_key and consumer_secret breaks POST requests #28

Open
beaumartinez opened this issue May 28, 2012 · 2 comments
Open

Comments

@beaumartinez
Copy link

I can't really write an example, but if you only specify the consumer_key and consumer_secret in the hook, POST requests don't send data, they send it as part of the query string (even though the data isn't present in request.params either).

I've tried similar code with restkit and it worked fine with that.

@beaumartinez
Copy link
Author

Okay, here's an adapted example.

Code:

import requests
from oauth_hook import OAuthHook

def oauth_session(consumer_key, consumer_secret):
    hook = OAuthHook(consumer_key=consumer_key, consumer_secret=consumer_secret)
    session = requests.session(hooks={'pre_request': hook})

    return session

session = oauth_session('key', 'secret')
response = session.get('http://127.0.0.1:8000/', params={'range': 1})

print response.request.headers
print response.request.data
print response.request.params
print response.request.oauth_params
print response.request.url

print

response = session.post('http://127.0.0.1:8000/', data={'range': 1})

print response.request.headers
print response.request.data
print response.request.params
print response.request.oauth_params
print response.request.url

Output:

{'Accept-Encoding': 'identity, deflate, compress, gzip', 'Accept': '*/*', 'User-Agent': 'python-requests/0.12.1'}
{}
{'range': 1}
{'oauth_nonce': '25120337', 'oauth_timestamp': '1338210292', 'oauth_consumer_key': 'key', 'oauth_signature_method': 'HMAC-SHA1', 'oauth_version': '1.0', 'oauth_signature': '5M7HIJBrYjsMChtjIhHVGsHNGms='}
http://127.0.0.1:8000/?oauth_nonce=25120337&oauth_timestamp=1338210292&oauth_consumer_key=key&oauth_signature_method=HMAC-SHA1&oauth_version=1.0&range=1&oauth_signature=5M7HIJBrYjsMChtjIhHVGsHNGms%3D

{'Accept-Encoding': 'identity, deflate, compress, gzip', 'Accept': '*/*', 'User-Agent': 'python-requests/0.12.1'}
{}
{}
{'oauth_nonce': '79275618', 'oauth_timestamp': '1338210292', 'oauth_consumer_key': 'key', 'oauth_signature_method': 'HMAC-SHA1', 'oauth_version': '1.0', 'oauth_signature': 'nJQCp00XZMp5PZv+MXdBio3uukY='}
http://127.0.0.1:8000/?oauth_nonce=79275618&oauth_timestamp=1338210292&oauth_consumer_key=key&oauth_signature_method=HMAC-SHA1&oauth_version=1.0&range=1&oauth_signature=nJQCp00XZMp5PZv%2BMXdBio3uukY%3D

Notice in particular the query string for the url in the POST example—data and params are both empty, but we have data added to the query string!

@beaumartinez
Copy link
Author

Thanks for your time :-) Aside form this one bug it's a great project; I'd hunt this down myself but I'm pretty busy otherwise.

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

1 participant