0

I want to develop an HttpTrigger function in VS Code but for each attempt to run & debug, I get this error message :

connect econnrefused 127.0.0.1:9091

I tried a lot of solutions detailled for others questions, but none of them worked. Here are my config infos :

  • VS Code : 1.79.0
  • Python : 3.10.11
  • Azure Functions Core Tools : 4.0.5198
  • Windows 10 Pro

Here are my files info :

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

It is as it was generated, I do not change anything and it still doesn't work.

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
        )

When I use run & debug, I get this : enter image description here

When I use a command line to start my function, I get this : enter image description here enter image description here enter image description here enter image description here enter image description here

There are many more MS_FUNCTION lines, but I think they are not useful. If someone knows how I can remove these prints, I would appreciate because no one had those when I was searching for an answer. The list of what I tried :

  • Change the port to 7071 or 9092
  • The 3 possibilities described here
  • I set the setting "terminal.integrated.shell.windows" on powershell.exe
  • Uninstall VS Code, Azure Functions Core Tools and Python, but it was useless
Grobln
  • 23
  • 6

1 Answers1

0

I have tried to reproduce the issue by using the same version of tools and it worked for me.

I am using the same versions too -

VS Code : 1.79.0

enter image description here

Python : 3.10.11

enter image description here

Azure Functions Core Tools : 4.0.5198

enter image description here

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
)

I got the below output

enter image description here

enter image description here

Ikhtesam Afrin
  • 897
  • 1
  • 1
  • 6
  • I followed what you did but nothing changed for me – Grobln Jun 12 '23 at 12:31
  • Please check this SO question https://stackoverflow.com/questions/75610213/how-do-i-debug-a-fastapi-azure-function-app-in-vscode/75627121#75627121 – Ikhtesam Afrin Jun 12 '23 at 12:43
  • I already tried all those possibilities but nothing work for me – Grobln Jun 12 '23 at 14:04
  • I tried to downgrade to python 3.10.0 but no changement either – Grobln Jun 12 '23 at 14:09
  • can you provide the error information as a text instead of screenshot, so that it will be easy to help – Ikhtesam Afrin Jun 13 '23 at 03:43
  • [2023-06-09T07:22:24.146Z] File "c:.\.vscode\extensions\ms-python.python-2023.10.0\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 493, in start_client [2023-06-09T07:22:24.147Z] s.connect((host, port)) [2023-06-09T07:22:24.149Z] ConnectionRefusedError: [WinError 10061] No connection could be established because the target computer expressly refused it [2023-06-09T07:22:24.150Z] Could not connect to 127.0.0.1: 53444 ... – Grobln Jun 14 '23 at 12:16
  • [2023-06-09T07:22:24.723Z] PublishSpecializationCompleteEvent failed with System.InvalidOperationException: An invalid request URI was provided. Either the request URI must be an absolute URI or BaseAddress must be set. [2023-06-09T07:22:24.724Z] at System.Net.Http.HttpClient.PrepareRequestMessage(HttpRequestMessage request) [2023-06-09T07:22:24.725Z] at System.Net.Http.HttpClient.CheckRequestBeforeSend(HttpRequestMessage request) – Grobln Jun 14 '23 at 12:16
  • [2023-06-09T07:22:24.725Z] at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken) [2023-06-09T07:22:24.726Z] at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request) [2023-06-09T07:22:24.726Z] at Microsoft.Azure.WebJobs.Script.WebHost.Management.MeshServiceClient.SendAsync(IEnumerable`1 formData) in /_/src/WebJobs.Script.WebHost/Management/MeshServiceClient.cs:line 154 – Grobln Jun 14 '23 at 12:17
  • [2023-06-09T07:22:24.727Z] at Microsoft.Azure.WebJobs.Script.WebHost.Management.MeshServiceClient.NotifyHealthEvent(ContainerHealthEventType healthEventType, Type source, String details) in /_/src/WebJobs.Script.WebHost/Management/MeshServiceClient.cs:line 104 [2023-06-09T07:22:24.727Z] at Microsoft.Azure.WebJobs.Script.WebHost.ContainerManagement.LinuxContainerActivityPublisher.PublishSpecializationCompleteEvent() in /\_/src/WebJobs.Script.WebHost/ContainerManagement/LinuxContainerActivityPublisher.cs:line 122 [2023-06-09T07:23:20.598Z] Starting worker process failed – Grobln Jun 14 '23 at 12:17
  • [2023-06-09T07:23:20.600Z] Microsoft.Azure.WebJobs.Script.Grpc: The operation has timed out. [2023-06-09T07:23:20.623Z] Failed to start a new language worker for runtime: python. [2023-06-09T07:23:20.780Z] PublishContainerActivity [2023-06-09T07:23:20.781Z] System.Net.Http: An invalid request URI was provided. Either the request URI must be an absolute URI or BaseAddress must be set. [2023-06-09T07:23:21.597Z] Failed to publish status to /memoryactivity [2023-06-09T07:23:21.598Z] System.Private.Uri: Invalid URI: The hostname could not be parsed. – Grobln Jun 14 '23 at 12:17
  • [2023-06-09T07:23:22.749Z] Language Worker Process exited. Pid=10368. [2023-06-09T07:23:22.750Z] py exited with code -1073741819 (0xC0000005). . [2023-06-09T07:23:34.664Z] Language Worker Process exited. Pid=2652. [2023-06-09T07:23:34.667Z] py exited with code -1073741819 (0xC0000005). .\ – Grobln Jun 14 '23 at 12:17
  • have you tried in any other editor? – Ikhtesam Afrin Jun 15 '23 at 10:57
  • I don't but I think I will need to do so – Grobln Jun 16 '23 at 06:23