容器 test_0_4cb91f00 未响应端口 8000 上的 HTTP ping,站点启动失败。查看容器日志进行调试

问题描述 投票:0回答:1

我正在尝试将 Echo 机器人从 botframework 的 microsoft 示例部署到 azure web 应用程序(python),每当我在成功部署后尝试测试它时,都会出现错误提示

向容器test_0_fea5f125发起预热请求进行现场测试 2023-11-09T09:25:00.574Z 错误 - 用于站点测试的容器 test_0_fea5f125 已退出,站点启动失败 2023-11-09T09:25:00.607Z 错误 - 容器 test_0_fea5f125 未响应端口 8000 上的 HTTP ping,站点启动失败。查看容器日志进行调试。

我尝试将 .net Echo 机器人部署到 azure web 应用程序,它工作正常,但 python 却不行,我尝试在 azure web 应用程序配置中添加 WEBSITES_PORT = 8000,但仍然遇到相同的错误。

python azure azure-web-app-service botframework chatbot
1个回答
0
投票

按照以下步骤创建 Echo Bot 并将其部署到 Azure 应用服务。

  • 引用了 MSDOC 并使用以下命令创建了 Echo Bot 应用程序
cookiecutter https://github.com/microsoft/BotBuilder-Samples/releases/download/Templates/echo.zip

Bot Framework 模拟器在本地响应:

enter image description here

  • 修改app.py
  • 中的以下代码
app = web.Application(middlewares=[aiohttp_error_middleware])
app.router.add_post("/api/messages", messages)

if __name__ == "__main__":
    try:
        web.run_app(app, host="0.0.0.0", port=CONFIG.PORT)
    except Exception as error:
        raise error

相反,添加以下代码取自SO

  • 感谢@jackygeee提供代码:
def init_func(argv):
    APP = web.Application(middlewares=[aiohttp_error_middleware])
    APP.router.add_post("/api/messages", messages)
    return APP
if __name__ == "__main__":
    APP = init_func(None)

    try:
        web.run_app(APP, host="0.0.0.0", port=CONFIG.PORT)
    except Exception as error:
        raise error
  • 创建 Azure BotAzure 应用服务
  • 转到
    Azure Bot=> Configuration
    ,通过在
    Messaging EndPoint 中添加 
    /api/messages(https://.azurewebsites.net/api/messages) 来粘贴 Web 应用程序的 URL。
  • 复制
    Microsoft App ID
    值。
  • 单击配置中的管理密码,创建新密码并复制其值(将在代码中用作
    Microsoft App password
    )。

enter image description here

  • 创建了一个秘密以使用其作为我的应用程序密码

enter image description here

  • 转到 Echo Bot 项目中的 Config.py 并粘贴如上所述复制的 App_IDApp_Password
import os
class DefaultConfig:
    """ Bot Configuration """

    PORT = 3978
    APP_ID = os.environ.get("MicrosoftAppId", "<Your_App_ID>")
    APP_PASSWORD = os.environ.get("MicrosoftAppPassword", "<Your_App-Password")
  • 将应用程序部署到 Azure 应用服务:

enter image description here

将应用程序部署到 Azure 后:

  • 导航到您的
    web app=>Settings=> Configuration =>General Settings=> Startup Command
    ,添加命令:
python3 -m aiohttp.web -H 0.0.0.0 -P 8000 app:init_func

enter image description here

  • 转到您的Azure Bot =>设置=>在网络聊天中测试并测试聊天:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.