【Azure 应用服务】Python fastapi Function在Azure中遇见AttributeError异常(AttributeError: 'AsgiMiddleware' object has no attribute 'handle_async')
问题描述
参考文档“Using FastAPI Framework with Azure Functions”, 使用FastAPI 模块在Function中实现API请求。通过VS Code本地运行成功。
但是部署到Azure Function App后,遇见了如下错误:
[2023-01-30T09:23:15.474Z] Executing 'Functions.WrapperFunction' (Reason='This function was programmatically called via the host APIs.', Id=f49afe7c-b128-463e-0e93-c2f41f15bbde)
[2023-01-30T09:23:15.588Z] Executed 'Functions.WrapperFunction' (Failed, Id=f49afe7c-b128-463e-0e93-c2f41f15bbde, Duration=145ms)
[2023-01-30T09:23:15.588Z] System.Private.CoreLib: Exception while executing function: Functions.WrapperFunction. System.Private.CoreLib: Result: Failure
[2023-01-30T09:23:15.588Z] Exception: AttributeError: 'AsgiMiddleware' object has no attribute 'handle_async'
关于AttributeError: 'AsgiMiddleware' object has no attribute 'handle_async'错误,有什么办法来解决呢?
问题解决
根据在Github上寻找到相同错误的Issue分析,这个错误与Python的版本有关,在Python 3.9有遇见,但升级使用Python 3.10时,问题得到解决。
此外,Function App也提供了另外一种方式来解决该问题:设置应用配置 PYTHON_ISOLATE_WORKER_DEPENDENCIES 的值为 1 。
可以参考下图,在Azure Function App的门户中,设置 PYTHON_ISOLATE_WORKER_DEPENDENCIES
参考资料
AttributeError: 'AsgiMiddleware' object has no attribute 'handle_async' when running locally #7:https://github.com/Azure-Samples/fastapi-on-azure-functions/issues/7
[END]
当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
2021-01-30 【Azure Developer】使用Microsoft Graph API创建用户时候遇见“401 : Unauthorized”“403 : Forbidden”