我试图在我的repl.it shell中制作一个简单的聊天机器人,但是它出错了,说它“不能自动确定凭据”,我已经看过它很多次了,也想不出怎么做。此外,我可能有其他的错误,但我不能说,因为我无法克服这个错误。如果有人能在这方面帮助我,或者你有一个我可以效仿的例子,那将是很棒的https://repl.it/@RyandaKing/ThoughtfulWorrisomeQuadrant。
import dialogflow
from google.api_core.exceptions import InvalidArgument
DIALOGFLOW_PROJECT_ID = 'newagent-1-rhjebl'
DIALOGFLOW_LANGUAGE_CODE = 'en-US'
GOOGLE_APPLICATION_CREDENTIALS = 'newagent-1-rhjebl-29ae80f7e64d.json'
SESSION_ID = '110497386060607202274'
text_to_be_analyzed = "Hello"
session_client = dialogflow.SessionsClient()
session = session_client.session_path(DIALOGFLOW_PROJECT_ID, SESSION_ID)
text_input = dialogflow.types.TextInput(text=text_to_be_analyzed, language_code=DIALOGFLOW_LANGUAGE_CODE)
query_input = dialogflow.types.QueryInput(text=text_input)
try:
response = session_client.detect_intent(session=session, query_input=query_input)
except InvalidArgument:
raise
print("Query text:", response.query_result.query_text)
print("Detected intent:", response.query_result.intent.display_name)
print("Detected intent confidence:", response.query_result.intent_detection_confidence)
print("Fulfillment text:", response.query_result.fulfillment_text)发布于 2019-12-11 19:07:36
原因是您不正确地使用了.json包含的私钥。正如所描述的这里,您应该定义具有.json密钥文件路径值的环境变量。
假设.py和.json文件位于同一个目录中,请按以下方式运行它。
$ cd path/to/app
$ env 'GOOGLE_APPLICATION_CREDENTIALS=newagent-1-rhjebl-29ae80f7e64d.json' python3 app.pyhttps://stackoverflow.com/questions/58703774
复制相似问题