“QueryResult”对象不可iterable无法将Dialogflow API中的值返回到my chatb

2024-09-30 03:21:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我无法返回response.query_result

我想返回result["action"]result["query_text"]["fulfillment_text"]

我试过response.query_result.fulfillment_text但是它显示出来了

"too many values to unpack"

response_id: "39a7bc01-2432-4de2-b134-6d7c5bbee6ea-f308a5c4"
query_result {
  query_text: "you annoy me"
  action: "smalltalk.agent.annoying"
  parameters {
  }
  all_required_params_present: true
  fulfillment_text: "I\'ll try not to annoy you."
  fulfillment_messages {
    text {
      text: "I\'ll try not to annoy you."
    }
  }
  intent {
    name: "projects/my-project-1560026125515/agent/intents/c50c7c63-aa76-4781-ba7d-d9ba4c93df64"
    display_name: "smalltalk.agent.annoying"
  }
  intent_detection_confidence: 1.0
  language_code: "en"
}

Tags: totextyouresponsenotactionresultquery
1条回答
网友
1楼 · 发布于 2024-09-30 03:21:54

您必须将响应转换为JSON格式。 对于此用途:

import google.protobuf  as pf

response =pf.json_format.MessageToJson(response)

现在可以解析这个JSON响应了。 希望有帮助

相关问题 更多 >

    热门问题