ARTICLE AD BOX
Please help me to understand the reason
My code is so and I recive this error, from the header
def create_access_token(**data: dict) -> str: to_encode = data.copy() expire = datetime.utcnow() + timedelta(minutes=50) to_encode.update({"exp": expire}) AbstractJWKBase.from_dict(to_encode) encoded_jwt = jwt.JWT().encode( AbstractJWKBase, settings.SECRET_KEY, alg=settings.ALGORITHM ) return encoded_jwtwhen I invoke original code it by code so
@router.post("/login") async def login_user(response: Response, email: EmailStr, password: str): user = await authenticate(email=email, password=password) if not user: raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED) access_token = create_access_token({"sub": user.id})If I remove ** from **data, I recive another error:
Error: payload must be a dict in AbstractJWKBase.from_dict(to_encode)
I have add print in function create_access_token so.
def create_access_token(data: dict) -> str: to_encode = data.copy() print("1", data, type(data)) expire = datetime.utcnow() + timedelta(minutes=50) to_encode.update({"exp": expire}) print("2",to_encode, type(to_encode)) AbstractJWKBase.from_dict(to_encode)And I recived
1 {'sub': 13} <class 'dict'> 2 {'sub': {'sub': 13}, 'exp': datetime.datetime(2026, 1, 18, 18, 51, 49, 144881)} <class 'dict'>But Python 3.9 says "payload must be a dict"
