GET 请求因有效访问令牌而失败

发布于 2025-01-18 14:50:57 字数 1973 浏览 1 评论 0原文

我在网站上有一个帐户:https://dev.yuride.network/
我将它用于测试目的。我遇到了一个特定的 API 问题
https://dev.yuride.network/api/users/me/< br> 我正在向上述 URL 发出 GET 请求并传递访问令牌,例如:
response = requests.get(url, headers={'accesstoken': accessToken})
访问令牌是通过 API 调用
获取的 https://dev.yuride.network/api/token/?name=xyz< /a> 并使用
传递有效负载数据 用户名密码此API已成功使用JSON返回访问令牌

{
"access":"asdsad",
"refresh":"asdasd"
}

,但请求requests.get(URL, headers={'accesstoken': accessToken})< /code> 失败
我不确定我是否以错误的方式传递标头,或者要使用的密钥应该是
与我使用的 accesstoken 不同,

我从检查选项卡复制了curl命令,同时从地址栏转到/api/user/me:

curl 'https://dev.yuride.network/api/users/me/' \
  -H 'authority: dev.yuride.network' \
  -H 'pragma: no-cache' \
  -H 'cache-control: no-cache' \
  -H 'sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="99", "Microsoft Edge";v="99"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "Windows"' \
  -H 'upgrade-insecure-requests: 1' \
  -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36 Edg/99.0.1150.55' \
  -H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \
  -H 'sec-fetch-site: none' \
  -H 'sec-fetch-mode: navigate' \
  -H 'sec-fetch-user: ?1' \
  -H 'sec-fetch-dest: document' \
  -H 'accept-language: en-US,en;q=0.9' \
  -H 'cookie: saml_session=aayrv7sksot1ooztihpht7svi5cydcet; csrftoken=6sQYPXR7ldqU5LCuR19DkUvsRbWmyll4TamiM4DqjKQdzWTh4u3TGkvI8ZwgGYbp; sessionid=5r6v6uk5vv3aufyt82np2guxn30pa3gu' \
  --compressed

上面的命令在bash shell上运行良好。它没有任何访问令牌

I have an account on the website: https://dev.yuride.network/
I am using it for testing purposes. There is a particular API that I am getting issues with
https://dev.yuride.network/api/users/me/
I am making GET request to the above URL and passing the access token like:
response = requests.get(url, headers={'accesstoken': accessToken})
The access token is obtained by making an API call to
https://dev.yuride.network/api/token/?name=xyz and passing payload data with
username and password this API is successfully returning the access token with JSON

{
"access":"asdsad",
"refresh":"asdasd"
}

But the request requests.get(URL, headers={'accesstoken': accessToken}) is failing
I am not sure if I am passing the header the wrong way or the key to be used should be
different than the accesstoken that I am using

I copied the curl command from the inspect tab while going to /api/user/me from the address bar :

curl 'https://dev.yuride.network/api/users/me/' \
  -H 'authority: dev.yuride.network' \
  -H 'pragma: no-cache' \
  -H 'cache-control: no-cache' \
  -H 'sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="99", "Microsoft Edge";v="99"' \
  -H 'sec-ch-ua-mobile: ?0' \
  -H 'sec-ch-ua-platform: "Windows"' \
  -H 'upgrade-insecure-requests: 1' \
  -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36 Edg/99.0.1150.55' \
  -H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9' \
  -H 'sec-fetch-site: none' \
  -H 'sec-fetch-mode: navigate' \
  -H 'sec-fetch-user: ?1' \
  -H 'sec-fetch-dest: document' \
  -H 'accept-language: en-US,en;q=0.9' \
  -H 'cookie: saml_session=aayrv7sksot1ooztihpht7svi5cydcet; csrftoken=6sQYPXR7ldqU5LCuR19DkUvsRbWmyll4TamiM4DqjKQdzWTh4u3TGkvI8ZwgGYbp; sessionid=5r6v6uk5vv3aufyt82np2guxn30pa3gu' \
  --compressed

The above command runs fine on bash shell. It doesn't have any access token

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文