Reputation: 188
I'm trying this code:
import requests
url_token = 'https://accounts.google.com/o/oauth2/token'
params = {
'code': request.values.get('code', '', type=str),
'client_id': app.config['SOCIAL_GOOGLE']['consumer_key'],
'client_secret': app.config['SOCIAL_GOOGLE']['consumer_secret'],
'redirect_uri': urllib.quote_plus("https://example.com/google/code"),
'grant_type': 'authorization_code'
}
out = requests.post(url_token, params=params)
using Python-Request in Flask. But I get error response:
ERROR - out={
"error" : "invalid_request",
"error_description" : "Required parameter is missing: grant_type"
}
It is standard POST request. Any hint why Google doesn't see grant_type parameter? Or is it misleading error message?
Upvotes: 0
Views: 2720
Reputation: 54078
params
is for adding query parameters to the URL in GET requests, data
is for passing data to POST requests so you should pass the form POST parameters as:
out = requests.post(url_token, data=params)
see the docs at: http://docs.python-requests.org/en/latest/user/quickstart/#more-complicated-post-requests
Upvotes: 1