You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署Bot Framework至Azure Web App:解决‘找不到属性app’错误

问题分析与解决方案

错误原因

Azure Web App部署Python应用时,默认会在入口文件(通常是app.py)中寻找名为app的ASGI/WSGI应用对象。你的代码中创建的应用对象是大写的APP,导致Azure无法识别,从而抛出“Failed to find attribute 'app' in 'app'”错误。此外,若未正确配置ASGI服务器启动命令,也可能触发此问题。

解决方案

1. 统一应用对象命名

将代码中的大写APP改为小写app,匹配Azure的默认查找规则:

# 替换原代码中的APP定义
app = web.Application(middlewares=[aiohttp_error_middleware])
app.router.add_post("/api/messages", messages)

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

2. 自定义启动命令(无需修改代码)

如果不想调整变量名,可以在Azure Web App中配置自定义启动命令,指定应用对象路径:

  • 进入Azure Portal,打开你的Web App资源
  • 导航到配置 > 常规设置
  • 在启动命令中输入:
    gunicorn -w 4 -k uvicorn.workers.UvicornWorker app:APP
    
    其中app:APP表示入口文件为app.py,应用对象为APP。

3. 确保依赖包含ASGI服务器

Azure Web App需要ASGI服务器来运行aiohttp应用,需在requirements.txt中添加相关依赖:

aiohttp>=3.8.0
botbuilder-core>=4.15.0
gunicorn>=20.1.0
uvicorn>=0.20.0

内容的提问来源于stack exchange,提问作者Volume069

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 20:03:16