收到无效的 JSON 负载。 'payload' 处的未知名称 \"row\":无法在 google automl api 上找到字段

Invalid JSON payload received. Unknown name \"row\" at 'payload': Cannot find field on google automl api

我正在尝试实施 google automl api: https://cloud.google.com/automl-tables/docs/predict

api 文档说我需要 post 以下格式的数据:

{
  "payload": {
    "row": {
     "values": [value1, value2,...]
         }
      }
}

但是当我使用相同格式的 post 数据时,出现以下错误:

{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unknown name \"row\" at 'payload': Cannot find field.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
    "@type": "type.googleapis.com/google.rpc.BadRequest",
    "fieldViolations": [
      {
        "field": "payload",
        "description": "Invalid JSON payload received. Unknown name \"row\" at 'payload': Cannot find field."
      }
    ]
      }
    ]
  }
}

这是我的 curl 请求:

curl --location --request POST 'https://automl.googleapis.com/v1/projects/project-id/locations/us-central1/models/TBLID:predict' \
--header 'Content-Type: application/json; charset=utf-8;' \
--header 'Accept-Charset: utf-8' \
--header 'Authorization: Bearer token here' \
--data-raw '{
 "payload": {
"row": {
  "values": [
    "",
    "4.900000",
    ""
  ]
}
 }
}'

我不确定是什么导致了这个错误。 谁能帮忙解决这个问题谢谢

我有一个包含 AutoML 表的项目,这是一个发送的预测请求示例,在其中工作正常并且 returns 结果没有错误:

{
  "payload": {
    "row": {
      "values": [
        "2",
        "test text",
        "test text",
        "21",
        "0",
        "0",
        "test text",
        "10",
        "",
        "S"
      ]
    }
  }
}

如果您不确定如何提交数据或遇到错误,请转到控制台中的项目和 AutoML Tables 模型,然后单击“测试和使用”。然后,按照 getting an online prediction from console 的这些说明进行操作。请注意 JSON 代码视图,它将为您提供准确的输入并让您测试您的 JSON 输入。

为了测试,我提交了以下 curl 请求(更改了一些标识字符)

curl -X POST \
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
https://automl.googleapis.com/v1beta1/projects/this-isnt-a-real-project-id/locations/us-central1/models/TBL123451234512345:predict

我发送请求的同一目录中的 request.json 文件是:

{
    "payload": {
      "row": {
        "values": [
          "yes",
          "-1",
          "primary",
          "jul",
          "51",
          "0",
          "yes",
          "no",
          "88",
          "cellular",
          "blue-collar",
          "unknown",
          "10",
          "620",
          "married"
        ]
      }
    }
  }

回复是:

{
  "payload": [
    {
      "tables": {
        "score": 0.9999906,
        "value": "no"
      }
    },
    {
      "tables": {
        "score": 9.42341e-06,
        "value": "yes"
      }
    }
  ]
}

我还在邮递员中成功地重复了同样的请求:

curl --location --request POST 'https://automl.googleapis.com/v1beta1/projects/this-isnt-a-real-project-id/locations/us-central1/models/TBL123451234512345:predict' \
--header 'Accept-Charset: utf-8' \
--header 'Authorization: Bearer abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd' \
--header 'Content-Type: application/json' \
--data-raw '{
    "payload": {
      "row": {
        "values": [
          "yes",
          "-1",
          "primary",
          "jul",
          "51",
          "0",
          "yes",
          "no",
          "88",
          "cellular",
          "blue-collar",
          "unknown",
          "10",
          "620",
          "married"
        ]
      }
    }
  }'

我复制了 Quickstart 并做了一些成功的 curl 请求,你的问题似乎与你的 json 请求的格式有关;因此,我推荐以下测试:

  1. 从您的 json 中删除换行符,然后再次发出请求:
curl --location --request POST 'https://automl.googleapis.com/v1/projects/project-id/locations/us-central1/models/TBLID:predict' \
--header 'Content-Type: application/json; charset=utf-8;' \
--header 'Accept-Charset: utf-8' \
--header 'Authorization: Bearer token-here' \
--data-raw '{ "payload": { "row": { "values": [ "", "4.900000", "" ] } } }'
  1. 将 json 保存在文件中并再次发出请求:
curl --location --request POST 'https://automl.googleapis.com/v1/projects/project-id/locations/us-central1/models/TBLID:predict' \
--header 'Content-Type: application/json; charset=utf-8;' \
--header 'Accept-Charset: utf-8' \
--header 'Authorization: Bearer token-here' \
-d @request.json

如果执行这些操作后问题仍然存在,我建议您联系 GCP support,以便他们可以在您的项目中分析您的问题。