AttributeError:模块“azure.durable_functions”没有属性“BluePrint”

问题描述 投票:0回答:2
import azure.durable_functions as df
bp_chat = df.BluePrint()

异常:AttributeError:模块“azure.durable_functions”没有属性“BluePrint”

现在azure.durable_functions的最新版本是1.2.6,我也尝试过它和1.2.3。但它们都不起作用。

我使用 BluePrint 在其他 python 文件中使用我的代码,没有它它就无法工作

我想运行我的 function_app.py,没有错误

azure pip attributeerror azure-durable-functions requirements.txt
2个回答
0
投票

请参阅我的 SO 线程答案,以在 Azure Functions 中使用蓝图。

蓝图方法不是 azure.durable_functions 的一部分,为了使蓝图正常工作,请按照此 MS Document

创建 2 个文件

我的function_app.py:-

import azure.functions as func 
from sidblueprint import bp

app = func.FunctionApp() 

app.register_functions(bp)

我的blueprint.py正在从function_app.py调用蓝图对象:-

import logging 

import azure.functions as func 

bp = func.Blueprint() 

@bp.route(route="default_template") 
def default_template(req: func.HttpRequest) -> func.HttpResponse: 
    logging.info('Python HTTP trigger function processed a request.') 

    name = req.params.get('name') 
    if not name: 
        try: 
            req_body = req.get_json() 
        except ValueError: 
            pass 
        else: 
            name = req_body.get('name') 

    if name: 
        return func.HttpResponse( 
            f"Hello, {name}. This HTTP-triggered function " 
            f"executed successfully.") 
    else: 
        return func.HttpResponse( 
            "This HTTP-triggered function executed successfully. " 
            "Pass a name in query or body" 
            " personalized response.", 
            status_code=200 
        )

输出:-

enter image description here

enter image description here

如果你想使用blueprint pip模块,直接安装参考这里


0
投票

我尝试了1.2.0,可以肯定它不包含蓝图。

但是在1.2.3版本中我在这个路径中发现了这个类 azure.durable_functions.decorators.durable_app.BluePrint()

我意识到 pip 没有正确更新模块。 我删除了 pip env,然后再次尝试使用

pip install azure-functions-durable==1.2.3
© www.soinside.com 2019 - 2024. All rights reserved.