Setting the decoder parameter in the get_auth_session function to json.loads when authenticating with google oauth2 returns an error
See original GitHub issueI have the following code token = request.GET.get(‘code’) data = { ‘code’: token, ‘redirect_uri’: ANGULAR_LOGIN_URL, ‘grant_type’: ‘authorization_code’} session = auth_manager.get_auth_session(data=data, decoder=json.loads)
which gives me the following error,
TypeError at /login/google/
can't use a string pattern on a bytes-like object
Request Method: GET
Request URL: http://127.0.0.1:8000/login/google/?code=4/dX8nbHWAW7WTMWr4zd6aigqygpvD.gn_o-kuFOPUcmmS0T3UFEsOglLpHhgI
Django Version: 1.6
Exception Type: TypeError
Exception Value:
can't use a string pattern on a bytes-like object
Exception Location: /usr/lib64/python3.3/json/decoder.py in decode, line 352
and the traceback
Environment:
Request Method: GET Request URL: http://127.0.0.1:8000/login/google/?code=4/dX8nbHWAW7WTMWr4zd6aigqygpvD.gn_o-kuFOPUcmmS0T3UFEsOglLpHhgI
Django Version: 1.6 Python Version: 3.3.2 Installed Applications: (‘django.contrib.admin’, ‘django.contrib.auth’, ‘django.contrib.contenttypes’, ‘django.contrib.sessions’, ‘django.contrib.messages’, ‘django.contrib.staticfiles’, ‘corsheaders’, ‘restless’, ‘blog’, ‘jobs’, ‘meetups’, ‘tweets’, ‘users’) Installed Middleware: (‘django.contrib.sessions.middleware.SessionMiddleware’, ‘django.middleware.common.CommonMiddleware’, ‘django.middleware.csrf.CsrfViewMiddleware’, ‘django.contrib.auth.middleware.AuthenticationMiddleware’, ‘django.contrib.messages.middleware.MessageMiddleware’, ‘django.middleware.clickjacking.XFrameOptionsMiddleware’, ‘corsheaders.middleware.CorsMiddleware’)
Traceback: File “/home/lucas/Programming/Python/Django/BoulderDjangoDev/venv/lib/python3.3/site-packages/django/core/handlers/base.py” in get_response
-
File “/home/lucas/Programming/Python/Django/BoulderDjangoDev/venv/lib/python3.3/site-packages/django/views/generic/base.py” in viewresponse = wrapped_callback(request, _callback_args, *_callback_kwargs)
-
File “/home/lucas/Programming/Python/Django/BoulderDjangoDev/venv/lib/python3.3/site-packages/django/views/generic/base.py” in dispatchreturn self.dispatch(request, _args, *_kwargs)
-
File “/home/lucas/Programming/Python/Django/BoulderDjangoDev/BoulderDjangoDev/oauth/views.py” in getreturn handler(request, _args, *_kwargs)
-
File “/home/lucas/Programming/Python/Django/BoulderDjangoDev/BoulderDjangoDev/oauth/views.py” in OAuth2Callbackrequest=request, account_type=GOOGLE, auth_manager=google_auth)
-
File “/home/lucas/Programming/Python/Django/BoulderDjangoDev/venv/lib/python3.3/site-packages/rauth/service.py” in get_auth_sessionsession = auth_manager.get_auth_session(data=data, decoder=json.loads)
-
File “/home/lucas/Programming/Python/Django/BoulderDjangoDev/venv/lib/python3.3/site-packages/rauth/service.py” in get_access_tokenreturn self.get_session(self.get_access_token(method, **kwargs))
-
File “/home/lucas/Programming/Python/Django/BoulderDjangoDev/venv/lib/python3.3/site-packages/rauth/service.py” in process_token_requestaccess_token, = process_token_request(r, decoder, key)
-
File “/usr/lib64/python3.3/json/init.py” in loadsdata = decoder(r.content)
-
File “/usr/lib64/python3.3/json/decoder.py” in decodereturn _default_decoder.decode(s)
-
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
Exception Type: TypeError at /login/google/ Exception Value: can’t use a string pattern on a bytes-like object
I’m not too sure why I am getting this error. I looked at
https://github.com/litl/rauth/issues/110
but that has not helped
Issue Analytics
- State:
- Created 10 years ago
- Comments:11 (6 by maintainers)
Top GitHub Comments
You can also pass in a custom decoder now. Closing.