Styria-Digital / django-rest-framework-jwt

JSON Web Token Authentication support for Django REST Framework
https://styria-digital.github.io/django-rest-framework-jwt/
MIT License
191 stars 57 forks source link

TypeError('Expected a string value') when creating a key #85

Open NiklasRz opened 3 years ago

NiklasRz commented 3 years ago

Hi all,

I just moved from the original version to this fork. I am getting the following error:

Internal Server Error: /api/api-token-auth/
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.7/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 480, in raise_uncaught_exception
    raise exc
  File "/usr/local/lib/python3.7/site-packages/rest_framework/views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/rest_framework_jwt/views.py", line 28, in post
    serializer.is_valid(raise_exception=True)
  File "/usr/local/lib/python3.7/site-packages/rest_framework/serializers.py", line 220, in is_valid
    self._validated_data = self.run_validation(self.initial_data)
  File "/usr/local/lib/python3.7/site-packages/rest_framework/serializers.py", line 422, in run_validation
    value = self.validate(value)
  File "/usr/local/lib/python3.7/site-packages/rest_framework_jwt/serializers.py", line 59, in validate
    'token': JSONWebTokenAuthentication.jwt_encode_payload(payload),
  File "/usr/local/lib/python3.7/site-packages/rest_framework_jwt/authentication.py", line 45, in jwt_encode_payload
    return api_settings.JWT_ENCODE_HANDLER(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/rest_framework_jwt/utils.py", line 130, in jwt_encode_payload
    return jwt.encode(payload, key, signing_algorithm, headers=headers, json_encoder=JSONEncoder).decode()
  File "/usr/local/lib/python3.7/site-packages/jwt/api_jwt.py", line 65, in encode
    json_payload, key, algorithm, headers, json_encoder
  File "/usr/local/lib/python3.7/site-packages/jwt/api_jws.py", line 113, in encode
    key = alg_obj.prepare_key(key)
  File "/usr/local/lib/python3.7/site-packages/jwt/algorithms.py", line 140, in prepare_key
    key = force_bytes(key)
  File "/usr/local/lib/python3.7/site-packages/jwt/utils.py", line 30, in force_bytes
    raise TypeError('Expected a string value')
TypeError: Expected a string value
[15/Feb/2021 13:49:46] "POST /api/api-token-auth/ HTTP/1.0" 500 133304

I uninstalled the old package and installed yours. Am I doing anything wrong?

melhindi commented 6 months ago

@NiklasRz were you able to find the problem?