【Azure 应用服务】Python fastapi Function在Azure中遇见AttributeError异常(AttributeError: 'AsgiMiddleware' object has no attribute 'handle_async')

简介: 【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

 

相关文章
|
20天前
|
Python
【Azure Developer】Python – Get Access Token by Azure Identity in China Azure Environment
【Azure Developer】Python – Get Access Token by Azure Identity in China Azure Environment
|
20天前
|
API 开发工具 网络架构
【Azure Developer】如何通过Azure Portal快速获取到对应操作的API并转换为Python代码
【Azure Developer】如何通过Azure Portal快速获取到对应操作的API并转换为Python代码
|
20天前
|
存储 Linux 开发工具
【Azure App Service】本地Git部署Python Flask应用上云(Azure App Service For Linux)关键错误
【Azure App Service】本地Git部署Python Flask应用上云(Azure App Service For Linux)关键错误
|
20天前
|
API 开发工具 网络架构
【Azure Developer】使用Python SDK去Azure Container Instance服务的Execute命令的疑问解释
【Azure Developer】使用Python SDK去Azure Container Instance服务的Execute命令的疑问解释
【Azure Developer】使用Python SDK去Azure Container Instance服务的Execute命令的疑问解释
|
20天前
|
Python
【Azure Function】发布 Python Function 到 Azure 成功,但是无法显示Function列表
【Azure Function】发布 Python Function 到 Azure 成功,但是无法显示Function列表
|
20天前
|
API C++ Python
【Azure Function】示例运行 python durable function(model V2)
【Azure Function】示例运行 python durable function(model V2)
|
20天前
|
API Python
【Azure Compute Gallery】使用 Python 代码从 Azure Compute Gallery 复制 Image-Version
【Azure Compute Gallery】使用 Python 代码从 Azure Compute Gallery 复制 Image-Version
|
20天前
|
Ubuntu Linux 测试技术
【Azure Function App】Python Function调用Powershell脚本在Azure上执行失败的案例
【Azure Function App】Python Function调用Powershell脚本在Azure上执行失败的案例
|
20天前
【Azure Durable Function】PowerShell Activity 函数遇见 Newtonsoft.Json.JsonReaderException: The reader's MaxDepth of 64 has been exceeded.
【Azure Durable Function】PowerShell Activity 函数遇见 Newtonsoft.Json.JsonReaderException: The reader's MaxDepth of 64 has been exceeded.
|
20天前
|
安全 JavaScript 应用服务中间件
【Azure Function App】如何修改Azure函数应用的默认页面呢?
【Azure Function App】如何修改Azure函数应用的默认页面呢?