PyJWT Token Cannot Be Decoded

I'm converting a deviceid to a JWT Token while a user is registering via their deviceid. Then I'm using the same JWTtoken in url request's header but Django just throws an error 'jwt.exceptions.DecodeError: Invalid header string: 'utf-8' codec can't decode byte 0xeb in position 1: invalid continuation byte ' eventhough I just created the JWTtoken using it. I checked online and that some people recommended it to converting UTF-8 but not sure if that would work or how to do it.

My Django


def deviceregistration(request,id):
    import time


    # print(type(jwttoken))      #here I checked and it's a string not a byte

    return JsonResponse({'jwttoken':jwttoken})    #it creates the instance and I can see the jwttoken

def manualwc(request,id):

    token=request.headers['token']  #I send a request with Postman with 'token' header and  in there {'deviceid':jwttoken I just created}
    print(type(token))               #it is still seen as string not byte
    decoded=jwt.decode(token, "test", algorithms=["HS256"])    #but it crashes here

#Then it should do something using decoded['deviceid'] but it crashes here
Back to Top