Azure-Function-Core-Tools With Proxy

286 Views Asked by At

I'm trying to run a local python function in Visual Studio code. I am under a proxy using a .pac file when executing the "func host start" command it gives me the following error:

Microsoft.Azure.WebJobs.Script: Error creating configuration in an external startup class. System.Net.Http: Proxy tunnel request to proxy 'http://{myProxy}:{portProxy}/' failed with status code '407'."

versions:

Found Python version 3.8.1 (py).

Azure Functions Core Tools Core Tools Version: 4.0.5382 Commit hash: N/A (64-bit) Function Runtime Version: 4.25.3.21264

Based on my research, I have seen that in some cases it works by adding the proxy in the local.settings.json file like this.

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "",
        "FUNCTIONS_WORKER_RUNTIME": "python",
        "AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
        "HTTP_PROXY": "http://{user}:{pass}@{myProxy}:{portProxy}/",
        "HTTPS_PROXY": "http://{user}:{pass}@enter code here{myProxy}:{portProxy}/",
        "NO_PROXY": "localhost,0.0.0.0,127.0.0.1"
    }
}

But I still have the error. I continue investigating on my part.

1

There are 1 best solutions below

2
Pravallika KV On

Set the HTTPS_PROXY and HTTP_PROXY in the environment variables to allow the VSCode to run the Azure function locally.

  • Run the below commands in Terminal to set the Https_Proxy and Http_Proxy in environment variable:
set HTTP_PROXY=http://{user}:{pass}@{myProxy}:{portProxy}/
set HTTPS_PROXY=http://{user}:{pass}@enter code here{myProxy}:{portProxy}/

(or)

  • Navigate to VSCode=>Settings=>Proxy and set the proxy in Http:Proxy.
  • Uncheck Http:Proxy Strict SSL.

These settings will be reflected in Settings.json:

{
"http.proxy": "http://{myProxy}:{portProxy}/",
"http.proxyStrictSSL": false
}
  • I have tried the same and the function executed without any issues:
(.venv) C:\Users\<username>\kpyv2fn>func host start
Found Python version 3.11.6 (py).

Azure Functions Core Tools
Core Tools Version:       4.0.5455 Commit hash: N/A  (64-bit)
Function Runtime Version: 4.27.5.21554

[2023-12-15T07:46:51.279Z] Customer packages not in sys path. This should never happen! 
[2023-12-15T07:46:53.059Z] Worker process started and initialized.

Functions:

        http_trigger:  http://localhost:7071/api/http_trigger

For detailed output, run func with --verbose flag.
[2023-12-15T07:47:00.219Z] Executing 'Functions.http_trigger' (Reason='This function was programmatically called via the host APIs.', Id=bca0454f-3fe8-477f-830c-34e9af0e6098)
[2023-12-15T07:47:00.326Z] Python HTTP trigger function processed a request.
[2023-12-15T07:47:00.483Z] Executed 'Functions.http_trigger' (Succeeded, Id=bca0454f-3fe8-477f-830c-34e9af0e6098, Duration=292ms)
[2023-12-15T07:47:01.876Z] Host lock lease acquired by instance ID '000000000000000000000000F72731CC'.