首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >必须初始化对话流CX位置设置- FAILED_PRECONDITION

必须初始化对话流CX位置设置- FAILED_PRECONDITION
EN

Stack Overflow用户
提问于 2021-05-28 15:40:09
回答 2查看 90关注 0票数 0

我正在使用Python客户端库自动化Dialogflow CX。这包括agent/intent/entity等。creation/updation/deletion.但在第一次运行时,我遇到了来自python的以下错误。

如果我登录控制台并从那里设置位置,然后重新运行代码,它可以正常工作。我可以创建代理。

遵循GCP的URL -

https://cloud.google.com/dialogflow/cx/docs/concept/region

我正在寻找代码,以自动化的区域和位置设置之前运行的python代码。请为我提供代码。

下面是我用来创建代理的代码。

代码语言:javascript
复制
Error -

google.api_core.exceptions.FailedPrecondition: 400 com.google.apps.framework.request.FailedPreconditionException: Location settings have to be initialized before creating the agent in location: us-east1. Code: FAILED_PRECONDITION

grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
        status = StatusCode.FAILED_PRECONDITION
        details = "com.google.apps.framework.request.FailedPreconditionException: Location settings have to be initialized before creating the agent in location: us-east1. Code: FAILED_PRECONDITION"
        debug_error_string = "{"created":"@1622183899.891000000","description":"Error received from peer ipv4:142.250.195.170:443","file":"src/core/lib/surface/call.cc","file_line":1068,"grpc_message":"com.google.apps.framework.request.FailedPreconditionException: Location settings have to be initialized before creating the agent in location: us-east1. Code: FAILED_PRECONDITION","grpc_status":9}"


main.py -

# Import Libraries
import google.auth
import google.auth.transport.requests
from google.cloud import dialogflowcx as df
from google.protobuf.field_mask_pb2 import FieldMask
import os, time
import pandas as pd

# Function - Authentication
def gcp_auth():
cred, project = google.auth.default(scopes=["https://www.googleapis.com/auth/cloud-platform"])
auth_req = google.auth.transport.requests.Request()
cred.refresh(auth_req)

# Function - Create Agent
def create_agent(agent_name, agent_description, language_code, location_id, location_path):
    if location_id == "global":
        agentsClient = df.AgentsClient()
    else:
        agentsClient = df.AgentsClient(client_options={"api_endpoint": f"{location_id}-dialogflow.googleapis.com:443"})
    agent = df.Agent(display_name=agent_name, description=agent_description, default_language_code=language_code, time_zone=time_zone, enable_stackdriver_logging=True)
    createAgentRequest = df.CreateAgentRequest(agent=agent, parent=location_path)
    agent = agentsClient.create_agent(request=createAgentRequest)
    return agent```
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-06-02 17:28:02

目前Dialogflow不支持通过API配置位置设置,因此无法通过其初始化位置设置。您只能通过控制台设置位置。

作为另一种选择,由于位置设置只需要为每个项目的每个区域初始化一次,因此您可以设置位置并自动执行代理创建过程,其中包括一些有用的链接:12

另一方面,如果你觉得这个特性有用,你可以提交一个特性请求,here。它将由谷歌的产品团队进行评估。

票数 1
EN

Stack Overflow用户

发布于 2021-06-18 01:09:55

非常感谢亚历山大·莫赖斯。我已经提出了同样的功能请求。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67734764

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档