Problem description
Python v3.6.6
Django v3.2.4
djangorestframework v3.12.4
djangorestframework-simplejwt v4.4.0
When testing the interface after running runserver
command, the error of background printing is as follows
Traceback (most recent call last):
File "D:\Program Files\Python36\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "D:\Program Files\Python36\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "D:\Program Files\Python36\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
return view_func(*args, **kwargs)
File "D:\Program Files\Python36\lib\site-packages\django\views\generic\base.py", line 70, in view
return self.dispatch(request, *args, **kwargs)
File "D:\Program Files\Python36\lib\site-packages\rest_framework\views.py", line 509, in dispatch
response = self.handle_exception(exc)
File "D:\Program Files\Python36\lib\site-packages\rest_framework\views.py", line 469, in handle_exception
self.raise_uncaught_exception(exc)
File "D:\Program Files\Python36\lib\site-packages\rest_framework\views.py", line 480, in raise_uncaught_exception
raise exc
File "D:\Program Files\Python36\lib\site-packages\rest_framework\views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
File "D:\Program Files\Python36\lib\site-packages\rest_framework_simplejwt\views.py", line 27, in post
serializer.is_valid(raise_exception=True)
File "D:\Program Files\Python36\lib\site-packages\rest_framework\serializers.py", line 220, in is_valid
self._validated_data = self.run_validation(self.initial_data)
File "D:\Program Files\Python36\lib\site-packages\rest_framework\serializers.py", line 422, in run_validation
value = self.validate(value)
File "D:\Program Files\Python36\lib\site-packages\rest_framework_simplejwt\serializers.py", line 75, in validate
data['refresh'] = str(refresh)
File "D:\Program Files\Python36\lib\site-packages\rest_framework_simplejwt\tokens.py", line 82, in __str__
return token_backend.encode(self.payload)
File "D:\Program Files\Python36\lib\site-packages\rest_framework_simplejwt\backends.py", line 43, in encode
return token.decode('utf-8')
AttributeError: 'str' object has no attribute 'decode'
terms of settlement
Method 1
Upgrade the djangorestframework simplejwt
version to 4.6.0 +
Method 2
Open
D:// program files/Python 36/lib/site packages/rest_ framework_ simplejwt\backends.py
File, edit line 43. take
return token.decode('utf-8')
It can be amended as follows
return token
explain
Read More:
- [Solved] django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.Did you install mysqlclie
- [Solved] AttributeError: ‘Manager‘ object has no attribute ‘get_by_natural_key‘
- Django Issues: TypeError: “Settings” object is irreversible
- [Solved] ValueError: check_hostname requires server_hostname
- visdom Install and Run Error: raise Connectionerror [How to Solve]
- [Solved] HTTPError: 404 Client Error: Not Found for url: https://huggingface.co/saved_model
- linux ubuntu pip search Fault: <Fault -32500: “RuntimeError: PyPI‘s XMLRPC API is currently disab
- Python Error: Failed to establish a new connection: [Errno -2] Name or service not known
- Pytorch ValueError: Expected more than 1 value per channel when training, got input size [1, 768
- [Solved] matplotlib.units.ConversionError: Failed to convert value(s) to axis units: ‘LiR‘
- Python 3.7 Error: AttributeError: ‘str‘ object has no attribute ‘decode‘ [How to Solve]
- Gunicorn Flask Error: [ERROR] Socket error processing request
- [Solved] Forbidden (403) CSRF verification failed. Request aborted.
- Python installs virtualenv through PIP and always reports an error: response.py“, line 438, in _error_catcher yield
- [Solved] socketio.exceptions.ConnectionError: OPEN packet not returned by server
- How to Fix “HTTP error 403: forbidden” in Python 3. X
- [Solved] Torch Build Module Error: NotImplementedError
- Mac Upgrade pip Error OSError: [Errno 13] Permission denied: ‘/Library/Python/2.7/site-packages/pip-9.0.1-py2….
- urllib.error.HTTPError: HTTP Error 403: Forbidden [How to Solve]
- [Solved] Python matplotlib Error: RuntimeError: In set_size: Could not set the fontsize…