我正在尝试实现google automl api https://cloud.google.com/automl-tables/docs/predict
api文档说我需要以以下格式发布数据
{
"payload": {
"row": {
"values": [value1, value2,...]
}
}
}
但是当我以相同格式发布数据时,出现以下错误。
{
"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 --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",
""
]
}
}
}'
我不确定导致此错误的原因。任何人都可以帮助解决这个问题
答案 0 :(得分:2)
我有一个带有AutoML表的项目,这是发送的示例预测请求,该请求可以正常运行并返回结果而不会出错:
{
"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"
]
}
}
}'
答案 1 :(得分:0)
我复制了Quickstart,并成功执行了一些curl请求,您的问题似乎与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", "" ] } } }'
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联系,以便他们可以在您的项目中分析您的问题。