Dialogflow v2 API在Python中进行身份验证失败

时间:2018-09-18 03:04:07

标签: python google-api google-oauth dialogflow

所以我的代码可以在控制台上运行,但是如果我尝试导入模块或在Web上运行代码,则会出现google.api_core.exceptions.ServiceUnavailable: 503 Deadline Exceeded错误。

def detect_intent_texts(project_id, session_id, texts, language_code):
    """Returns the result of detect intent with texts as inputs.

    Using the same `session_id` between requests allows continuation
    of the conversaion."""
    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)

        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 (detect_intent_texts('newagent-38239', '12121211', ['Hi there'], 'en-US'))

我有身份验证设置和环境变量GOOGLE_APPLICATION_CREDENTIALS设置。就像我之前说过的那样,代码可以在控制台上运行,或者如果我尝试运行类似python main.py的程序,则可以运行。如果我尝试导入模块或在Web服务器上运行它,则会失败:

0 个答案:

没有答案