Chainlink

如何修復 Chainlink 外部適配器的錯誤 422

  • December 8, 2021

我為 API 建構了一個外部適配器,並將其部署為 GCP 上的雲功能。但是,當我向部署的外部適配器發送 Curl 命令時,它會返回錯誤 422。以下是我嘗試訪問的 API 的文件、外部適配器的程式碼以及我發送的 curl 命令。我一直在關注本教程並使用他們在此處提供的模板:https ://blog.chain.link/build-and-use-external-adapters/ 任何人都可以發現問題出在哪里以及如何解決它以獲取數據從適配器回來?

API 文件(我正在嘗試訪問“統計”端點):https ://shamba-gateway-staging-2ycmet71.ew.gateway.dev/geoapi/v1/docs

外部適配器程式碼:

https://github.com/shambadynamic/meanExternalAdapter/blob/main/index.js

使用上面的程式碼連結到已部署的外部適配器:

https://europe-west6-shamba-vpc-host-nonprod.cloudfunctions.net/geoEA-mean

我發送的捲曲命令:

curl -X POST -H "content-type:application/json" "https://europe-west6-shamba-vpc-host-nonprod.cloudfunctions.net/geoEA-mean" --data '{ "id": 0, "data": {"dataset_code":"COPERNICUS/S2_SR", "selected_band":"NDVI", "image_scale":250.0, "start_date":"2021-09-01", "end_date":"2021-09-10", "geometry":{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[19.51171875,4.214943141390651],[18.28125,-4.740675384778361],[26.894531249999996,-4.565473550710278],[27.24609375,1.2303741774326145],[19.51171875,4.214943141390651]]]}}]}} }'

發送上述 curl 命令時收到的錯誤消息:

"name":"AdapterError","message":"Request failed with status code 422"

從您提供的 API 文件中,如果錯誤程式碼為 422,則響應如下所示:

{
 "detail": [
   {
     "loc": [
       "string"
     ],
     "msg": "string",
     "type": "string"
   }
 ]
}

執行相同的命令,但將輸出保存在文本文件 ( curl ... >> output.txt) 中,然後讀取實際錯誤

curl -X POST -H "content-type:application/json" "https://europe-west6-shamba-vpc-host-nonprod.cloudfunctions.net/geoEA-mean" --data '{ "id": 0, "data": {"dataset_code":"COPERNICUS/S2_SR", "selected_band":"NDVI", "image_scale":250.0, "start_date":"2021-09-01", "end_date":"2021-09-10", "geometry":{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[19.51171875,4.214943141390651],[18.28125,-4.740675384778361],[26.894531249999996,-4.565473550710278],[27.24609375,1.2303741774326145],[19.51171875,4.214943141390651]]]}}]}} }' >> output.txt

發現問題。請求超時太快。向適配器 index.js 程式碼添加了超時參數,如下所示。似乎已經解決了問題。

const config = { 方法:‘post’,url,數據,超時:3600000 }

引用自:https://ethereum.stackexchange.com/questions/115040