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

Azure Function Python V2无法被Azure Logic App引用的问题求助

解决Azure Function Python V2在Logic App中引用报错:Cannot be called from a logic app. It must not have a custom route

问题场景

使用VS Code生成的默认Python V2 Azure Function代码,未修改时在Azure Logic App中引用该函数,会触发错误:Cannot be called from a logic app. It must not have a custom route。尝试修改route参数值或仅指定methods参数,均无法解决问题。

原因分析

Python V2 Azure Function中,显式指定@app.route(route="xxx")会被平台标记为自定义路由,而Logic App的Azure Function内置连接器会校验这一属性,拒绝调用带有自定义路由的函数。即使route值与函数名一致,平台仍会判定为自定义路由,导致报错。

解决方案

移除@app.route中的route参数,让函数使用默认路由规则(路由路径为/api/<函数名>),具体修改如下:

修改后的完整代码

import azure.functions as func
import logging

app = func.FunctionApp(http_auth_level=func.AuthLevel.FUNCTION)

# 移除route参数,使用默认路由(对应函数名test_http)
@app.route()
def test_http(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 executed successfully.")
    else:
        return func.HttpResponse(
             "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
             status_code=200
        )

补充说明

如果需要限制HTTP请求方法,可在@app.route()中添加methods参数,例如:

@app.route(methods=["POST"])

只要不指定route参数,就不会触发自定义路由的校验错误,Logic App即可正常调用该函数。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 12:01:29