我尝试在 Azure 门户上使用 python 部署我的 azure 函数,但出现错误“未找到 HTTP 触发器”,它在 vs code 中工作,我尝试使用默认的 http 触发器函数,它工作得很好。
我添加了
app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)
@app.route(route="http_trigger")
这仍然面临问题。 还降级了 VS Code 中的 Azure Functions 核心工具。
未找到 HTTP 触发器
最初,我在将函数部署到 azure 门户时也遇到了同样的错误。
AzureWebJobsFeatureFlags:EnableWorkerIndexing
应用程序设置并重新部署了该功能。然后它就按预期工作了。我已经使用运行时堆栈python创建了Http触发函数。检查下面的功能代码:
功能代码:
import azure.functions as func
import logging
app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)
@app.route(route="http_trigger")
def http_trigger(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
)
local.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "your-storage conn-string",
"FUNCTIONS_WORKER_RUNTIME": "python",
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing"
}
}
我在门户中创建了一个包含消费计划的功能应用程序,并将该功能部署到门户中。检查以下配置:
以上功能已成功部署到azure门户中。检查下面:
输出: