i am developing web app related to election and try to implement authorize token concept using rest_framework_simplejwt.serializers
and while running this code i encounter error related to str
class like this:
AttributeError: 'str' object has no attribute 'decode'
from this part of code:
data['refresh'] = str(refresh)
class AuthTokenObtainSerializer(TokenObtainPairSerializer):
"""
Seializer for th user authentication object.
Returns
-------
json: 'access' and 'token'
"""
default_error_messages = {
'no_active_account': _('No active account found with the given credentials') # noqa: E501
}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['password'] = serializers.CharField(
style={'input_type': 'password'},
trim_whitespace=False
)
self.fields['face_image'] = serializers.ImageField()
def validate(self, attrs):
"""
Validates and authenticate the user.
"""
citizenship_number = attrs.get('citizenship_number')
password = attrs.get('password')
face_image = attrs.get('face_image')
face_id = FaceIdAuthBackend()
user = face_id.authenticate(
citizenship_number=citizenship_number,
password=password,
face_id=face_image
)
if user is None or not user.is_active:
raise exceptions.AuthenticationFailed(
self.error_messages['no_active_account'],
'no_active_account',
)
update_last_login(None, user)
data = {}
refresh = self.get_token(user)
data['refresh'] = str(refresh)
data['access'] = str(refresh.access_token)
return data
please help me regarding this......