Object of type 'AuthToken' is not JSON serializable
so you must change token value from AuthToken.objects.create(obj) to AuthToken.objects.create(obj)[1]
beacause AuthToken return a tuple and you need just token
class KnoxSerializer(TokenSerializer):
def get_token(self, obj):
try:
from knox.models import AuthToken
except ImportError:
warnings.warn('django-rest-knox must be installed for Knox authentication', ImportWarning)
raise
token = AuthToken.objects.create(obj)[1]
return token
Hi, when I use knox i get this error :
Object of type 'AuthToken' is not JSON serializable so you must change token value from AuthToken.objects.create(obj) to AuthToken.objects.create(obj)[1] beacause AuthToken return a tuple and you need just token
class KnoxSerializer(TokenSerializer): def get_token(self, obj): try: from knox.models import AuthToken except ImportError: warnings.warn('django-rest-knox must be installed for Knox authentication', ImportWarning) raise token = AuthToken.objects.create(obj)[1] return token