I am trying to incorporate this package into a REST API developed in Python 3.6.9. What version should I use?
When installing the package without specifying the version I get the following:
djangorestframework-simplejwt-4.4.0
pyjwt-2.0.1
but it fails to request the token.
Internal Server Error: /api/token/
Traceback (most recent call last):
File "/home/humberto/.virtualenvs/Versat-ERP/lib/python3.6/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/humberto/.virtualenvs/Versat-ERP/lib/python3.6/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/humberto/.virtualenvs/Versat-ERP/lib/python3.6/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, callback_args, *callback_kwargs)
File "/home/humberto/.virtualenvs/Versat-ERP/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
return view_func(args, *kwargs)
File "/home/humberto/.virtualenvs/Versat-ERP/lib/python3.6/site-packages/django/views/generic/base.py", line 71, in view
return self.dispatch(request, args, *kwargs)
File "/home/humberto/.virtualenvs/Versat-ERP/lib/python3.6/site-packages/rest_framework/views.py", line 483, in dispatch
response = self.handle_exception(exc)
File "/home/humberto/.virtualenvs/Versat-ERP/lib/python3.6/site-packages/rest_framework/views.py", line 443, in handle_exception
self.raise_uncaught_exception(exc)
File "/home/humberto/.virtualenvs/Versat-ERP/lib/python3.6/site-packages/rest_framework/views.py", line 480, in dispatch
response = handler(request, args, *kwargs)
File "/home/humberto/.virtualenvs/Versat-ERP/lib/python3.6/site-packages/rest_framework_simplejwt/views.py", line 27, in post
serializer.is_valid(raise_exception=True)
File "/home/humberto/.virtualenvs/Versat-ERP/lib/python3.6/site-packages/rest_framework/serializers.py", line 236, in is_valid
self._validated_data = self.run_validation(self.initial_data)
File "/home/humberto/.virtualenvs/Versat-ERP/lib/python3.6/site-packages/rest_framework/serializers.py", line 437, in run_validation
value = self.validate(value)
File "/home/humberto/.virtualenvs/Versat-ERP/lib/python3.6/site-packages/rest_framework_simplejwt/serializers.py", line 75, in validate
data['refresh'] = str(refresh)
File "/home/humberto/.virtualenvs/Versat-ERP/lib/python3.6/site-packages/rest_framework_simplejwt/tokens.py", line 82, in __str__
return token_backend.encode(self.payload)
File "/home/humberto/.virtualenvs/Versat-ERP/lib/python3.6/site-packages/rest_framework_simplejwt/backends.py", line 43, in encode
return token.decode('utf-8')
AttributeError: 'str' object has no attribute 'decode'
For Python 3.6 the last version available is 4.4.0. You can check the Changelog.
The error 'str' object has no attribute 'decode' is common in version 4.4.0. I recommend you upgrade to Python 3.7 so you can use version 4.6.0
Thanks for the reply. At the moment I cannot migrate to python 3.7. I am tested in Python 3.6 djangorestframework-simplejwt == 4.4.0 with PyJWT == 1.7.1 and it works fine. As soon as I can migrate to the newer versions of python I will update to version 4.6.0 of djangorestframework-simplejwt. Regards
There hasn't been too much change regarding dependencies in SimpleJWT + PyJWT upgrades. It's ok to stay on Python 3.6, but I'd imagine you would want to upgrade to Python 3.8.7 at this point to stay up to date with Python itself.
I'm just wondering, why would one deprecate Python 3.6 support before the EOL of the latter.
@barseghyanartur the intention is push everyone to move to more advanced Python versions so we wouldn't have to maintain compatibility for Python 3.6 and so we can take advantage of new stuff (like the walrus operator), even if it's not completely out of support. To me, it wasn't really necessary for a simple library like this one (out of my hands at the time), but I don't really see a point to regressing and maintaining support for 3.6 now now that EOL for 3.6 is this year.
@Andrew-Chen-Wang:
I wonder, who makes such decisions (and how)? For a project like this (2.4K stars, ~450K downloads per month) being backwards compatible is a must. At least, don't drop non EOL software support until it's really EOL.
Consider this a shout.
@barseghyanartur the original owner of the repository before it was migrated to Jazzband. As for the how, I gave his logic above. Thanks for the shout.
@Andrew-Chen-Wang:
Fair enough. Thanks for your patience. :)