首页 > 解决方案 > 获取请求时获取请求错误 422

问题描述

我看过一些关于此的帖子,但其中大多数都使用 requests.post 并且我想要一个获取请求。

我正在制作一个程序,它只是转到一个 url 并获取一个订单列表。

这是示例响应:

{
  "page": 1,
  "pageCount": 22,
  "orderCount": 214,
  "orders": [
    {
      "id": "c1497823-370c-4c7a-82cd-dacddb36fc30",
      "productId": "1a641ba5-38df-4acb-86f7-f5c031e538a0",
      "email": "demoemail@autobuy.io",
      "ipAddress": "127.0.0.1",
      "total": 18,
      "currency": "USD",
      "gateway": "Stripe",
      "isComplete": true,
      "createdAtUtc": "2019-10-15T01:44:10.5446599+00:00"
    },
    {
      "id": "228f4ca4-5001-4c19-8350-f960f13d35a7",
      "productId": "a0041cc0-2bc6-40a2-9084-5880bae5ecec",
      "email": "demoemail@autobuy.io",
      "ipAddress": "127.0.0.1",
      "total": 50,
      "currency": "USD",
      "gateway": "Stripe",
      "isComplete": true,
      "createdAtUtc": "2019-10-15T01:43:17.8322919+00:00"
    },
    {
      "id": "71aed9b2-4bd2-4a49-9e6a-82119e6e05bf",
      "productId": "2e0ac75b-bfea-42f1-ad60-ead17825162a",
      "email": "demoemail@autobuy.io",
      "ipAddress": "127.0.0.1",
      "total": 6,
      "currency": "USD",
      "gateway": "Stripe",
      "isComplete": true,
      "createdAtUtc": "2019-10-14T23:54:44.6217478+00:00"
    }
  ]
}

这就是我得到的:

<Response [422]>

我的代码:

import requests
url = "https://autobuy.io/api/Orders?page=1"

headers = {
    "Cache-Control": "no-cache",
    "Pragma": "no-cache",
    "APIKey": "<APIKEY>"
}
req = requests.get(url, headers=headers)

print(req)

我正在尝试使用的 api 文档https://api.autobuy.io/?version=latest

编辑:在他们的网站上说

HEADERS
APIKey
2cdbdc48-b297-41ad-a234-329db0d2dbea

AutoBuy Api Key found in your shop settings

但是当我删除我的Cache-ControlPragma标头时,我收到一个与我的标头被缓存有关的错误(因为该站点位于 CDN 后面?)

标签: pythonpython-requests

解决方案


最终成为网站中的错误,我的仪表板显示无效密钥。


推荐阅读