Ошибка атрибута: объект ‘str’ не имеет атрибута ‘detect_intent’

#python #dialogflow-es

# #python #dialogflow-es

Вопрос:

Программное обеспечение / Пакет — Dialogflow

Я пытаюсь запустить код из строки 34-61, как показано в https://github.com/googleapis/dialogflow-python-client-v2/blob/master/samples/detect_intent_texts.py

Тем не менее, я получаю проблему в строке :

 response = session_client.detect_intent(session=session, query_input=query_input)
 

Я попытался переустановить библиотеку, но ошибка сохранялась даже после попытки на другом компьютере.

 import dialogflow_v2 as dialogflow
session_client = dialogflow.SessionsClient()

session = session_client.session_path(project_id, session_id)
print('Session path: {}n'.format(session))

for text in texts:
    text_input = dialogflow.types.TextInput(
        text=text, language_code=language_code)

    query_input = dialogflow.types.QueryInput(text=text_input)

    # ERROR IN THE FOLLOWING LINE
    response = session_client.detect_intent(
        session=session, query_input=query_input)

    print('=' * 20)
    print('Query text: {}'.format(response.query_result.query_text))
    print('Detected intent: {} (confidence: {})n'.format(
        response.query_result.intent.display_name,
        response.query_result.intent_detection_confidence))
    print('Fulfillment text: {}n'.format(
        response.query_result.fulfillment_text))
 

Любые предложения о том, как я могу это решить?

Вот все сообщение об ошибке:

 AttributeError                            Traceback (most recent call last)
<ipython-input-5-15e77dd35618> in <module>
     10     query_input = dialogflow.types.QueryInput(text=text_input)
     11 
---> 12     response = session_client.detect_intent(session=session, query_input=query_input)
     13 
     14     print('=' * 20)

~/conda/lib/python3.6/site-packages/dialogflow_v2/gapic/sessions_client.py in detect_intent(self, session, query_input, query_params, input_audio, retry, timeout, metadata)
    255             self._inner_api_calls[
    256                 'detect_intent'] = google.api_core.gapic_v1.method.wrap_method(
--> 257                     self.transport.detect_intent,
    258                     default_retry=self._method_configs['DetectIntent'].retry,
    259                     default_timeout=self._method_configs['DetectIntent']

AttributeError: 'str' object has no attribute 'detect_intent'
 

Комментарии:

1. Это точный код, который терпит неудачу? Отсюда все выглядит нормально.

2. Да, это точный код. Код кажется нормальным, но когда я пытаюсь его запустить, появляется ошибка.