Токен PyJWT не может быть декодирован

Я конвертирую deviceid в JWT Token, когда пользователь регистрируется по своему deviceid. Затем я использую тот же JWTtoken в заголовке url запроса, но Django просто выбрасывает ошибку 'jwt.exceptions.DecodeError: Invalid header string: 'utf-8' codec can't decode byte 0xeb in position 1: invalid continuation byte ', хотя я только что создал JWTtoken, используя его. Я проверил в Интернете, что некоторые люди рекомендуют конвертировать UTF-8, но не уверен, что это сработает или как это сделать.

Мой Django urls.py:

urlpatterns=[
    path('manual/<str:id>/',views.manualwc),
    path('deviceregister/<str:id>/',views.deviceregistration)]

views.py:

def deviceregistration(request,id):
    import time
    deviceid=id

    jwttoken=jwt.encode({'deviceid':deviceid},"test",algorithm="HS256")

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

    newdevice=models.Anonym(created=time.strftime("%Y-%m-%d"),deviceid=id)
    newdevice.save()    
    
    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(token)
    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
Вернуться на верх