TokenRefreshView返回状态代码500,而不是访问令牌

2024-10-03 04:29:05 发布

您现在位置:Python中文网/ 问答频道 /正文

According to this Documentation.如果 您想从刷新令牌获取新的访问令牌。您需要像这样使用请求方法POST:

curl \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{"refresh":"somerefreshtokenhere"}' \
  http://localhost:8000/api/token/refresh/

反过来,我在django中使用此代码在每次访问令牌过期时刷新令牌:

requests.post(url="somekindofurl/refresh-view"
                                             ,headers={"Content-Type": "application/json"},
                                             data={"refresh": variable.refresh_token})

但是,, 这将返回状态为500 internal server error的完整HTML页面。然而,每当我尝试使用邮递员时,它都成功了enter image description here

如您所见,它按预期返回访问令牌。请注意,我使用的链接和使用的刷新令牌是相同的。我不知道是什么原因导致它返回500状态错误


Tags: to方法tokenjsonapplication状态documentationtype