【发布时间】:2022-01-17 14:54:13
【问题描述】:
我正在尝试从下面的代码中检索数据。 令牌是正确的,当我通过 ThunderClient 尝试时,我收到了数据。 但是在运行下面的代码时,我收到 401 - Unauthorized, Authentication Required。
由于我还在学习 Python,我不明白为什么它不起作用。
有人可以告诉我如何解决它吗? 非常感谢!
import requests
import json
import urllib.request
import os.path
import os
bearer_token="908yt"
headersAuth = {"Authorization": "Bearer {}".format(bearer_token)}
response = requests.get("https://mywebsiteexaple.com/api/", headers=headersAuth)
payload=response.json()
print(payload)
【问题讨论】:
-
网址无效
-
对不起,我的错。代码是401!我已经在 vscode 上通过 ThunderClient 进行了尝试,我收到了数据,我得到了 202。但是运行我的脚本时我的脚本不起作用。
-
网址只是一个例子。
-
您的代码没有发现任何问题,您正在正确传递 Bearer 令牌。如果可以分享有关您从 ThunderClient 访问的请求的详细信息,可能会更容易排除故障。
标签: python cookies bearer-token