requests / requests-oauthlib

OAuthlib support for Python-Requests!
https://requests-oauthlib.readthedocs.org/
ISC License
1.73k stars 423 forks source link

LinkedIn OAuth 2 Tutorial Example - Not working #137

Closed Michelcyc closed 10 years ago

Michelcyc commented 10 years ago

I tried the example and I've got a InsecureTransportError when using the method "fetch_token". I corrected this error by:

import os os.environ['DEBUG'] = '1'

Then, I've tried it again and I got a InvalidRequestError this time. My code is exactly like the example. My call is linkedin.fetch_token(token_url, client_secret=client_secret,authorization_response=redirect_response)

Stack errors:

InvalidRequestError Traceback (most recent call last)

in () ----> 1 linkedin.fetch_token(token_url, client_secret=client_secret,authorization_response=redirect_response) /Users/michelsiqueirareis/anaconda/lib/python2.7/site-packages/requests_oauthlib/oauth2_session.pyc in fetch_token(self, token_url, code, authorization_response, body, auth, username, password, **kwargs) 158 r = hook(r) 159 --> 160 self._client.parse_request_body_response(r.text, scope=self.scope) 161 self.token = self._client.token 162 log.debug('Obtained token %s.', self.token) /Users/michelsiqueirareis/anaconda/lib/python2.7/site-packages/oauthlib/oauth2/rfc6749/clients/web_application.pyc in parse_request_body_response(self, body, scope) 269 .. _`Section 7.1`: http://tools.ietf.org/html/rfc6749#section-7.1 270 """ --> 271 self.token = parse_token_response(body, scope=scope) 272 self._populate_attributes(self.token) 273 return self.token /Users/michelsiqueirareis/anaconda/lib/python2.7/site-packages/oauthlib/oauth2/rfc6749/parameters.pyc in parse_token_response(body, scope) 302 params['expires_at'] = time.time() + int(params['expires_in']) 303 --> 304 validate_token_parameters(params, scope) 305 return params 306 /Users/michelsiqueirareis/anaconda/lib/python2.7/site-packages/oauthlib/oauth2/rfc6749/parameters.pyc in validate_token_parameters(params, scope) 309 """Ensures token precence, token type, expiration and scope in params.""" 310 if 'error' in params: --> 311 raise_from_error(params.get('error'), params) 312 313 if not 'access_token' in params: /Users/michelsiqueirareis/anaconda/lib/python2.7/site-packages/oauthlib/oauth2/rfc6749/errors.pyc in raise_from_error(error, params) 229 for _, cls in inspect.getmembers(sys.modules[__name__], inspect.isclass): 230 if cls.error == error: --> 231 raise cls(**kwargs) InvalidRequestError: This example is 11 months old, maybe something changed and I don't know =/
ib-lundgren commented 10 years ago

Hi,

Did you have any luck with this? I just ran the example at http://requests-oauthlib.readthedocs.org/en/latest/examples/linkedin.html and it worked nicely.

Did you register and submit the same redirect url? Make sure to check trailing /. Try catch the error and print err.json

fyi, 'DEBUG' is transitioning to the more explicit 'OAUTHLIB_INSECURE_TRANSPORT'.

denibertovic commented 10 years ago

@ib-lundgren i ran the example from the link and when redirected to linkedin I get:

"Error code: ERR_CONTENT_DECODING_FAILED"

denibertovic commented 10 years ago

Wow this is an unbelievably confusing error message to get for a wrongly copy pasted client_id. The example is working for me now.

ib-lundgren commented 10 years ago

@denibertovic indeed. Glad you found the error :)

@Michelcyc closing this issue as I am unable to reproduce. Feel free to reopen with reproduction steps!