【问题标题】:Python request headers. error authenticating with JSON WEB TOKENPython 请求标头。使用 JSON WEB TOKEN 进行身份验证时出错
【发布时间】:2022-08-07 00:53:13
【问题描述】:

我正在通过构建一个简单的交易机器人来学习 python。我在尝试使用 JWT 进行身份验证时收到此错误

{
  \"error\": {
    \"status\": 403,
    \"message\": \"Authentication credentials were not provided.\"
  }
}

按照这里的例子https://docs.ledgerx.com/reference/tradedcontracts

import requests

url = \"https://api.ledgerx.com/trading/contracts/traded\"

headers = {
    \"Accept\": \"application/json\",
    \"Authorization\": \"MY_API_KEY\"
}

response = requests.get(url, headers=headers)

print(response.text)

现在我稍后插入字符串文字,我将此值存储在 .env 中

感谢您花时间阅读

  • 嗨@cmg,你能试试我的答案,让我知道它是否有效!

标签: python python-requests jwt request-headers


【解决方案1】:

你能试试这个吗

import requests

url = "https://api.ledgerx.com/trading/contracts/traded"

headers = {
    "Accept": "application/json",
    "Authorization": "JWT MY_API_KEY"
}

response = requests.get(url, headers=headers)

print(response.text)

【讨论】:

    猜你喜欢
    • 2017-10-14
    • 2018-02-16
    • 1970-01-01
    • 2019-09-23
    • 2010-12-03
    • 2014-06-21
    • 1970-01-01
    • 2014-10-02
    • 1970-01-01
    相关资源
    最近更新 更多