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:
- Python 3.7 Error: AttributeError: ‘str‘ object has no attribute ‘decode‘ [How to Solve]
- [Solved] AttributeError: ‘str‘ object has no attribute ‘decode‘
- [Solved] AttributeError: ‘str‘ object has no attribute ‘decode‘
- [Solved] Pytorch-transformers Error: AttributeError: ‘str‘ object has no attribute ‘shape‘
- AttributeError str object has no attribut [How to Solve]
- [Solved] AttributeError: ‘Manager‘ object has no attribute ‘get_by_natural_key‘
- [Solved] Paramiko error: AttributeError: ‘NoneType’ object has no attribute ‘time’
- [Solved] Python 3.6 Error: ‘dict’ object has no attribute ‘has_key’
- [Solved] Operator Not Allowed In Graph Error & Attribute Error Tensor object has no attribute numpy
- [Solved] pandas ExcelWrite AttributeError: ‘NoneType‘ object has no attribute ‘group‘
- [Solved] AttributeError: ‘NoneType‘ object has no attribute ‘astype‘
- [Solved] AttributeError: ‘DataFrame‘ object has no attribute ‘tolist‘
- [Solved] django AttributeError: ‘UserComment‘ object has no attribute ‘save‘
- [Solved] PyQt: RuntimeError: wrapped C/C++ object has been deleted & has no attribute of flush in python
- [Solved] Django Error: Attributeerror: ‘wsgirequest’ object has no attribute ‘is_ajax ‘
- [Solved] Add-apt-repository Command Error: AttributeError: ‘Thread‘ object has no attribute ‘isAlive‘
- [Solved] AttributeError: ‘_IncompatibleKeys’ object has no attribute
- [Solved] AttributeError WriteOnlyWorksheet object has no attribute cell
- [Solved] AttributeError: DataFrame object has no attribute’xxx’
- AttributeError: DatetimeProperties object has no attribute