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

TypeError when accessing simple view #470

Closed
jaydabi opened this issue Oct 7, 2021 · 3 comments
Closed

TypeError when accessing simple view #470

jaydabi opened this issue Oct 7, 2021 · 3 comments

Comments

@jaydabi
Copy link

jaydabi commented Oct 7, 2021

Getting a Token works as expected, but as soon as I try to access this simple view

class TestAPIView(APIView):
    permission_classes = (IsAuthenticated,)

    def get(self, request):
        return Response('test')

I get a TypeError.

Traceback (most recent call last):
  File "/home/user/PycharmProjects/project_x/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/user/PycharmProjects/project_x/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/user/PycharmProjects/project_x/venv/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/home/user/PycharmProjects/project_x/venv/lib/python3.8/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/user/PycharmProjects/project_x/venv/lib/python3.8/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/home/user/PycharmProjects/project_x/venv/lib/python3.8/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/home/user/PycharmProjects/project_x/venv/lib/python3.8/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/home/user/PycharmProjects/project_x/venv/lib/python3.8/site-packages/rest_framework/views.py", line 497, in dispatch
    self.initial(request, *args, **kwargs)
  File "/home/user/PycharmProjects/project_x/venv/lib/python3.8/site-packages/rest_framework/views.py", line 414, in initial
    self.perform_authentication(request)
  File "/home/user/PycharmProjects/project_x/venv/lib/python3.8/site-packages/rest_framework/views.py", line 324, in perform_authentication
    request.user
  File "/home/user/PycharmProjects/project_x/venv/lib/python3.8/site-packages/rest_framework/request.py", line 227, in user
    self._authenticate()
  File "/home/user/PycharmProjects/project_x/venv/lib/python3.8/site-packages/rest_framework/request.py", line 380, in _authenticate
    user_auth_tuple = authenticator.authenticate(self)
  File "/home/user/PycharmProjects/project_x/venv/lib/python3.8/site-packages/rest_framework_simplejwt/authentication.py", line 40, in authenticate
    validated_token = self.get_validated_token(raw_token)
  File "/home/user/PycharmProjects/project_x/venv/lib/python3.8/site-packages/rest_framework_simplejwt/authentication.py", line 94, in get_validated_token
    return AuthToken(raw_token)
  File "/home/user/PycharmProjects/project_x/venv/lib/python3.8/site-packages/rest_framework_simplejwt/tokens.py", line 43, in __init__
    self.payload = token_backend.decode(token, verify=verify)
  File "/home/user/PycharmProjects/project_x/venv/lib/python3.8/site-packages/rest_framework_simplejwt/backends.py", line 90, in decode
    return jwt.decode(
TypeError: decode() got an unexpected keyword argument 'verify'
[07/Oct/2021 12:39:52] "GET /api/test HTTP/1.1" 500 127928

When I uncomment line 94 of file rest_framework_simplejwt/backends.py it will return the view as expected.

The test request is build manually like this:

curl --location --request GET '127.0.0.1:8000/api/test' \
--header 'Authorization: Bearer token.goes.here' \
--data-raw ''

Settings look like below.

SIMPLE_JWT = {
    'ACCESS_TOKEN_LIFETIME': timedelta(minutes=5),
    'REFRESH_TOKEN_LIFETIME': timedelta(days=1),
    'VERIFYING_KEY': open('test_pubkey').read(),
    'SIGNING_KEY': open('test_privatekey').read(),
    'ALGORITHM': 'RS256',
}

Any clues on what I am missing?

@mbl-sme
Copy link

mbl-sme commented Oct 7, 2021

I am getting the same now on functions that have previously worked.
On my old virtual environment everything is fine but when I pip install the package fresh this error pops up.

@jaydabi
Copy link
Author

jaydabi commented Oct 7, 2021

Seems to be related to new PyJWT Version ( #467 (comment) ).

Confirmed.

return jwt.decode(token, self.verifying_key, algorithms=[self.algorithm], verify=verify,
TypeError: decode() got an unexpected keyword argument 'verify'

Quick fix is to set PyJWT==2.1.0 in your requirements.

Setting PyJWT==2.1.0 in requirements will workaround this.

@jaydabi jaydabi closed this as completed Oct 7, 2021
@mbl-sme
Copy link

mbl-sme commented Oct 7, 2021

Awesome, thanks @jaydabi

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

2 participants