0

我们有这样的 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
4

1 回答 1

1

当您收到错误时,您需要阅读错误消息。

它为您提供context: in step "returnResult"

错误意味着输出中不存在${bitresult.body[0]}该位置。0

Bit.ly 返回一个 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/",
}

所以它没有 abody[0]相反它有body.link

于 2020-10-16T18:18:26.113 回答