我正在尝试将 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,但仍然遇到相同的错误。
按照以下步骤创建 Echo Bot 并将其部署到 Azure 应用服务。
cookiecutter https://github.com/microsoft/BotBuilder-Samples/releases/download/Templates/echo.zip
Bot Framework 模拟器在本地响应:
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。
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 Bot=> Configuration
,通过在 Messaging EndPoint 中添加
/api/messages
Microsoft App ID
值。Microsoft App 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 后:
web app=>Settings=> Configuration =>General Settings=> Startup Command
,添加命令:python3 -m aiohttp.web -H 0.0.0.0 -P 8000 app:init_func