【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 #7https://github.com/Azure-Samples/fastapi-on-azure-functions/issues/7

 

[END]

 

posted @   路边两盏灯  阅读(184)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
历史上的今天:
2021-01-30 【Azure Developer】使用Microsoft Graph API创建用户时候遇见“401 : Unauthorized”“403 : Forbidden”
点击右上角即可分享
微信分享提示