运行Azure Function时遇connect econnrefused 127.0.0.1:9091错误求助
Azure Functions调试报错:connect econnrefused 127.0.0.1:9091
在VS Code中开发HttpTrigger类型的Azure Function,每次运行调试都会出现以下错误:
connect econnrefused 127.0.0.1:9091
已尝试多种同类问题的解决方案,但均无效。以下是环境配置:
- VS Code:1.79.0
- Python:3.10.11
- Azure Functions Core Tools:4.0.5198
- Windows 10 Pro
项目文件信息
launch.json
{ "version": "0.2.0", "configurations": [ { "name": "Python: Current file", "type": "python", "request": "launch", "program": "${file}", "console": "integratedTerminal" }, { "name": "Azure Functions", "type": "python", "request": "attach", "port": 9091, "preLaunchTask": "func: host start" } ] }
settings.json
{ "azureFunctions.deploySubpath": ".", "azureFunctions.scmDoBuildDuringDeployment": true, "azureFunctions.pythonVenv": ".venv", "azureFunctions.projectLanguage": "Python", "azureFunctions.projectRuntime": "~4", "debug.internalConsoleOptions": "neverOpen", "azureFunctions.showDeprecatedStacks": true, "azureFunctions.showHiddenStacks": true }
tasks.json
{ "version": "2.0.0", "tasks": [ { "type": "func", "label": "func: host start", "command": "host start", "problemMatcher": "$func-python-watch", "isBackground": true, "dependsOn": "pip install (functions)" }, { "label": "pip install (functions)", "type": "shell", "osx": { "command": ". ${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt" }, "windows": { "command": ". ${config:azureFunctions.pythonVenv}\\Scripts\\python -m pip install -r requirements.txt" }, "linux": { "command": ". ${config:azureFunctions.pythonVenv}/bin/python -m pip install -r requirements.txt" }, "problemMatcher": [] } ] }
init.py
使用生成时的默认内容,未做任何修改:
import logging import azure.functions as func def main(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 )
相关截图
调试报错截图:
命令行启动函数输出截图:




已尝试的解决方案
- 将调试端口改为7071或9092
- 尝试过针对同类问题的三种配置方案
- 将VS Code的
terminal.integrated.shell.windows设置为powershell.exe - 卸载重装VS Code、Azure Functions Core Tools和Python
额外问题
命令行输出中有大量MS_FUNCTION相关日志,求去除方法,搜索时未见到其他用户出现此情况。
内容的提问来源于stack exchange,提问作者Grobln
相关产品推荐
相关产品推荐

