Этот вопрос закрыт для ответов, так как повторяет вопрос Как в Python обращаться к Dialog Flow?
Wolf_Yout
@Wolf_Yout

Как исправить эту ошибку?

Пытаюсь воспользоваться библиотекой dialogflow для создания чат-бота, вот код который я взял с сайта:
import os
import dialogflow
from google.api_core.exceptions import InvalidArgument

os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "secret_key.json"

DIALOGFLOW_PROJECT_ID = 'My ID'
DIALOGFLOW_LANGUAGE_CODE = 'ru'
SESSION_ID = 'DEPO12014'

text_to_be_analyzed = "Привет!)"

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)

Файл secret_key на месте, но мне выдаёт такую ошибку:

Traceback (most recent call last):
File "C:\Users\shits\AppData\Local\Programs\Python\Python39\lib\site-packages\google\api_core\grpc_helpers.py", line 65, in error_remapped_callable
return callable_(*args, **kwargs)
File "C:\Users\shits\AppData\Local\Programs\Python\Python39\lib\site-packages\grpc\_channel.py", line 946, in __call__
return _end_unary_response_blocking(state, call, False, None)
File "C:\Users\shits\AppData\Local\Programs\Python\Python39\lib\site-packages\grpc\_channel.py", line 849, in _end_unary_response_blocking
raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.PERMISSION_DENIED
details = "Dialogflow API has not been used in project 787000836274 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/dia... then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry."
debug_error_string = "UNKNOWN:Error received from peer ipv4:173.194.222.95:443 {created_time:"2022-10-08T18:13:45.370623+00:00", grpc_status:7, grpc_message:"Dialogflow API has not been used in project 787000836274 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/dia... then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry."}"
>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Users\shits\Desktop\ChatBot\main.py", line 18, in
response = session_client.detect_intent(session=session, query_input=query_input)
File "C:\Users\shits\AppData\Local\Programs\Python\Python39\lib\site-packages\dialogflow_v2\gapic\sessions_client.py", line 269, in detect_intent
return self._inner_api_calls['detect_intent'](
File "C:\Users\shits\AppData\Local\Programs\Python\Python39\lib\site-packages\google\api_core\gapic_v1\method.py", line 154, in __call__
return wrapped_func(*args, **kwargs)
File "C:\Users\shits\AppData\Local\Programs\Python\Python39\lib\site-packages\google\api_core\retry.py", line 283, in retry_wrapped_func
return retry_target(
File "C:\Users\shits\AppData\Local\Programs\Python\Python39\lib\site-packages\google\api_core\retry.py", line 190, in retry_target
return target()
File "C:\Users\shits\AppData\Local\Programs\Python\Python39\lib\site-packages\google\api_core\timeout.py", line 210, in func_with_timeout
return func(*args, **kwargs)
File "C:\Users\shits\AppData\Local\Programs\Python\Python39\lib\site-packages\google\api_core\grpc_helpers.py", line 67, in error_remapped_callable
raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.PermissionDenied: 403 Dialogflow API has not been used in project 787000836274 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/dia... then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry. [links {
description: "Google developers console API activation"
url: "https://console.developers.google.com/apis/api/dia..."
}
, reason: "SERVICE_DISABLED"
domain: "googleapis.com"
metadata {
key: "consumer"
value: "projects/787000836274"
}
metadata {
key: "service"
value: "dialogflow.googleapis.com"
}
]
  • Вопрос задан
  • 138 просмотров
Решения вопроса 1
fenrir1121
@fenrir1121
Начни с документации
Dialogflow API has not been used in project 787000836274 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/dia... then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.

Научиться пользоваться переводчиком. Затем читать документацию вместо копирования кода, там дана инструкция из 4 шагов что нужно сделать со всеми ссылками
Ответ написан
Ваш ответ на вопрос

Вопрос закрыт для ответов и комментариев

Потому что уже есть похожий вопрос.
Похожие вопросы