我有权访问一个API,我试图开始利用它来自动化一些任务,然后我跳进它,但被JWT阻止,这是我从未使用过的。我也是一两年没有使用python,所以我有点生疏。请多多包涵。发送JWT使用python获取包含用户名/密码的请求
下面是从API文档直接引:
The authentication mode for an organization is with a JSON Web Token. Users
must pass a JSON Web Token (JWT) in the header of each API request made.
To obtain the JWT, send the user’s API key (UUID) and password in a JSON Web
Token GET Request. The authorization method of “Bearer” and a
space is then prefixed to the encoded token string returned. The token will
be tied to the user account that generated the JWT.
我已经试过requests
但我得到405错误,我也安装有进口pyjwt
但它的混乱给我。实际上,这就是我想要通过Python发送:
POST https://<our endpoint>/v1/token/get HTTP/1.1
Content-Type: application/json
{
"username": "<myUsername>",
"password": "<myPassword>"
我已经验证了目标API工作,因为有一小部分,如果没有JWT工作功能,并通过requests
欢迎提供建议,因为任何教程。我试过阅读几个JWT教程,但我很难将其翻译成python。
谢谢!
1.大多数情况下,我知道令牌端点需要一个POST(您尝试过),但上面的描述是关于GET的。你能找出更多吗? 2.带有密码的令牌请求通常如下所示:(在POST正文中)“grant_type = password&username = admin&password = 123”,所以也许你必须用uuid替换用户名? 3.一旦你获得了一个令牌,你必须像这样将令牌添加到每个请求的头部:“授权:承载者”(这是唯一的东西,这里很清楚,如果你有问题,请编辑你的问题。更多信息或取得任何进展 –
jps
4。获得工具提琴手,这将节省一些时间,当你试图找出你的请求的正确格式,并且只有当你把你的请求翻译成python时,你才能知道。 – jps