运行Azure Function时出现错误“connect econnrefused 127.0.0.1:9091”

pnwntuvh  于 2023-06-24  发布在  其他
关注(0)|答案(1)|浏览(112)

我想在VS Code中开发一个HttpTrigger函数,但每次尝试运行和调试时,我都会收到以下错误消息:
连接econnrejected 127.0.0.1:9091
我尝试了很多详细的解决方案,但没有一个工作。以下是我的配置信息:

  • VS代码:1.79.0
  • 简体中文(zh_cn)
  • Azure功能核心工具:4.0.5198
  • Windows 10专业版

以下是我的文件信息:

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
        )

当我使用run & debug时,我得到了这个:

当我使用命令行来启动函数时,我得到这样的结果:

还有更多的MS_FUNCTION行,但我认为它们没有用。如果有人知道我怎么能删除这些指纹,我会很感激,因为没有人有那些当我在寻找答案。我尝试的列表:

  • 将端口更改为7071或9092
  • 描述的3种可能性here
  • 我在powershell.exe上设置了“terminal.integrated.shell.windows”
  • 卸载VS Code、Azure Functions Core Tools和Python,但没有用
qvk1mo1f

qvk1mo1f1#

    • 我尝试使用相同版本的工具重现此问题,结果对我有效。**

我也用了同样的版本--

    • VS代码:1.79.0**

    • Python:3.10.11**

    • Azure Functions核心工具:4.0.5198**

    • launch.json**
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Python 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"
}
    • 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": []
}
]
}
    • local. settings. json**
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME": "python"
}
}
    • host.json**
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
}
}

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
)
    • 我得到了下面的输出**

相关问题