Cloud Workflows: TypeError: dictionary key must be a string; got: int
Cloud Workflows: TypeError: dictionary key must be a string; got: int
我们有这样的 Cloud Workflows 配方设置:
- readWikipedia:
call: http.post
args:
url: https://api-ssl.bitly.com/v4/shorten
headers:
Authorization: "Bearer <token>"
Content-type: "application/json"
body:
domain: bit.ly
long_url: https://cloud.google.com/blog
result: bitresult
- returnResult:
return: ${bitresult.body[0]}
我们得到一个错误:TypeError: dictionary key must be a string; got: int
这是我们得到的完整回复:
argument: 'null'
endTime: '2020-10-16T17:40:17.595823493Z'
error:
context: in step "returnResult"
payload: '{"message":"TypeError: dictionary key must be a string; got: int","tags":["TypeError"]}'
name: projects/985596417983/locations/us-central1/workflows/http_post/executions/5bfc56c0-b498-4149-9d28-2c0d51295a9a
startTime: '2020-10-16T17:40:17.297154818Z'
state: FAILED
workflowRevisionId: 000006-e18
当您遇到错误时,您需要阅读错误信息。
它为您提供 context: in step "returnResult"
错误意味着 ${bitresult.body[0]}
位置 0
在输出中不存在。
Bit.ly returns 一个 json 文档,例如:
{
"archived":false,
"created_at":"2020-10-16T17:40:17+0000",
"id":"bit.ly/35452TM",
"link":"//bit .ly/35452TM",
"long_url":"https://cloud.google.com/blog/",
}
所以它没有 body[0]
而是 body.link
我们有这样的 Cloud Workflows 配方设置:
- readWikipedia:
call: http.post
args:
url: https://api-ssl.bitly.com/v4/shorten
headers:
Authorization: "Bearer <token>"
Content-type: "application/json"
body:
domain: bit.ly
long_url: https://cloud.google.com/blog
result: bitresult
- returnResult:
return: ${bitresult.body[0]}
我们得到一个错误:TypeError: dictionary key must be a string; got: int
这是我们得到的完整回复:
argument: 'null'
endTime: '2020-10-16T17:40:17.595823493Z'
error:
context: in step "returnResult"
payload: '{"message":"TypeError: dictionary key must be a string; got: int","tags":["TypeError"]}'
name: projects/985596417983/locations/us-central1/workflows/http_post/executions/5bfc56c0-b498-4149-9d28-2c0d51295a9a
startTime: '2020-10-16T17:40:17.297154818Z'
state: FAILED
workflowRevisionId: 000006-e18
当您遇到错误时,您需要阅读错误信息。
它为您提供 context: in step "returnResult"
错误意味着 ${bitresult.body[0]}
位置 0
在输出中不存在。
Bit.ly returns 一个 json 文档,例如:
{
"archived":false,
"created_at":"2020-10-16T17:40:17+0000",
"id":"bit.ly/35452TM",
"link":"//bit .ly/35452TM",
"long_url":"https://cloud.google.com/blog/",
}
所以它没有 body[0]
而是 body.link