Cannot launch debugger for azure function app in vs code - python

I am trying to debug an azure function app in VSCode using Python in a Windows10 environment. Whenever I launch the debugger it hangs for a long period of time and then opens a message box that says
ECONNREFUSED 127.0.0.1:9091
There are a bunch of posts about this but none seem helpful/can solve the problem. Here is what I've tried:
uninstalling and re-installing different versions of
azure-function-core-tools using windows installer, npm and chocolatey
uninstalling and re-installing Azure Functions extension in VS Code
changing the extension bundle
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[3.3.0, 4.0.0)"
}
modifying local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "python"
}
}
deleting C:\Users\admin.azure-functions-core-tools\Functions\ExtensionBundles
creating a function app from command line using "func init" and lauching debugger by running "func host start" in active venv
I am using Python38 and really have no idea what else to try. Any suggestions are welcome.
Thanks!

Cannot launch debugger for azure function app in VScode-
ECONNREFUSED 127.0.0.1:9091
This type of generic error may occur for a variety of reasons.
Need to check and modify:
First and foremost, check whether the versions of Azure functions core tools and Pip are upgraded to the current version:
To upgrade pip:
python -m pip install --upgrade pip
To install and upgrade azure-functions:
pip install azure-functions
Go to the below path,
view -> Command palette -> User Settings
Python functions, task runFunctionsHost windows command only work with powershell:
Set the integrated > default profile: Windows to PowerShell as PowerShell runtime host is functional with Python functions. It was previously set to "null".
The debug configuration is specified in your tasks.json and launch.json files in the .vscode folder.
As stated here , the default listening port in launch.json is set to 9091. Here, I updated it to "port: 7071" which is open for traffic on my function project, launched the files, and then executed the "Attach to Python Functions" debug task once again.
Under .VScode folder -> launch.json file, this configuration changes works for me.
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "python_modules./.bin/func",
"console": "integratedTerminal"
},
{
"name": "Attach to Python Functions",
"type": "python",
"request": "attach",
"port": 7071,
"preLaunchTask": "func: host start"
}
]
}
Added multiple debug points, debugged and triggered successfully as shown below:
Also Check here for more approaches given by #Hari Krishna

found the solution at:
https://github.com/Azure/azure-functions-core-tools/issues/3160#issuecomment-1266273749
I ran command func start in verbose mode
func start --verbose
from there it was clear that the process timed out when trying to download a new extension bundle. Most likely due to slow internet. I manually installed the new extension bundle:
https://functionscdn.azureedge.net/public/ExtensionBundles/Microsoft.Azure.Functions.ExtensionBundle/3.15.0/Microsoft.Azure.Functions.ExtensionBundle.3.15.0_any-any.zip
(the full path should be in the --verbose output) and extracted to
C:\Users[user name].azure-functions-core-tools\Functions\ExtensionBundles\Microsoft.Azure.Functions.ExtensionBundle\3.15.0
It now works. Thanks everyone for input.

Related

VS Code's Python Debugger doesn't hit the breakpoint for Odoo 10

I use VS Code extension Python version 2.2x, Python interpreter version 2.7x, and use Odoo 10 of the latest version. I'm using WSL with Ubuntu 18.4 LTS.
I cannot debug the custom modules my company creates. I've specified the module's path in the argument, and it does run but it's not breaking at the breakpoints I specified.
Here's my launch.json:
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "/home/ihsansfd/odoo/odoo-bin",
"python": "/usr/bin/python",
"args": [
"--db_port=5434",
"--addons-path=/mnt/d/kuliah/odoo/repo/MUK/base,/mnt/d/kuliah/odoo/repo/MUK/core,/mnt/d/kuliah/odoo/repo/MUK/modifier",
],
"console": "integratedTerminal",
"justMyCode": true
},
Aside from request launch, I also tried attach and using a pip library debugpy for that but it's still only running without debugging.
I am really sure that it should hit the breakpoint because I've set a print statement there and it printed!
Any help would be appreciated. If you need any further detail please do ask.
Although you mentioned you've tried using attach with debugpy, I'm sharing my configuration since attach and debugpy is what I use every day without any issues.
Here is the shell command I use to run odoo via debugpy.
python3 /debug/debugpy --listen 0.0.0.0:5678 <odoo-bin-path> <odoo-args>
Change python3 to just python for your use case. Also change 0.0.0.0:5678 to whatever you need as well. I like to run Odoo inside a Docker container, and that's also the reason why I prefer to simply attach to the process rather than launching it right from VS Code.
I installed debugpy to /debug/debugpy using this command:
python3 -m pip install debugpy -t /debug
Here is the launch configuration I use in my launch.json:
{
"name": "Attach to Odoo",
"type": "python",
"justMyCode": false,
"request": "attach",
"host": "localhost",
"port": 5678,
"pathMappings": [
...
I need path mapping for my setup to map the
location of my local Odoo source code directory
to the location of the Odoo source code directory
inside of the Docker container. Depending on your
setup, you might be able to just skip this option.
...
]
}
Hopefully this helps!

Azure Functions deployment fails because pip install cannot find environment variable / app setting

EDIT: My flaw when deploying to Azure was that I was not saving the new Application settings I was introducing facepalm. Saving PIP_EXTRA_INDEX_URL=https://<token>#raw.githubusercontent.com/<gituser> allows pip to finally install my private library.
However, it still doesn't work when locally debugging with F5 on VSCode, regardless of my local.settings.json. Below I'll describe the hack that makes it work locally, but I would prefer to resolve why it doesn't work from my local settings.
My requirements.txt indicates the private library as <package_name> # https://raw.githubusercontent.com/<gituser>/<repo>/<branch>/dist/<package_name>0.1.11-py3-none-any.whl. Based on the fact that adding an PIP_EXTRA_INDEX_URL in Azure allows the deployment, I am trying to imitate that in my local.settings.json:
{
"IsEncrypted": false,
"Values": {
...
"PIP_EXTRA_INDEX_URL": "https://<token>#raw.githubusercontent.com/<gituser>",
...
}
}
However, I get a 404 error when the Azure's pip tries to install from requirements.txt.
Locally, in tasks.json, if I set that env var before I run pip install, the F5 starts working:
{
"version": "2.0.0",
"tasks": [
{
"type": "func",
"command": "host start",
"problemMatcher": "$func-python-watch",
"isBackground": true,
"dependsOn": "pip install (functions)"
},
{
"label": "pip install (functions)",
"type": "shell",
"osx": {
...
"windows": {
"command": "$env:PIP_EXTRA_INDEX_URL = 'https://<token>#raw.githubusercontent.com/<gituser>'; ${config:azureFunctions.pythonVenv}\\Scripts\\python -m pip install -r requirements.txt"
},
...
}
]
}
In other words, my F5 is not reading the env var from local.settings.json before the pip install task runs (note that the function itself is properly receiving the env vars as evidenced by successful os.environ[] calls). Also note that locally it does work if I set the env var in tasks.json, which is not ideal. I prefer my local.settings.json to mirror my Application settings on Azure.
In this issue it has been confirmed that this is expected behavior and that my workaround is valid:
"local.settings.json" is unique to core tools and thus only applies
during the func start command. Since "pip install" happen before
func start, you would have to set the env var elsewhere (and yes
tasks.json is a good place).

How to debug remote python code from local windows vs code

I want to debug python code (on remote linux) in local windows with VS code.
I did as follows:
In windows VS code, I can open remote linux python project using SSH.
Installed python debug tool ptvsd both in windows and remote linux.
Add code below in python project:
import ptvsd
ptvsd.enable_attach(address = ('$linux_ip', $port))
ptvsd.wait_for_attach()
Project launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Remote Attach",
"type": "python",
"request": "attach",
"connect": {
"host": "$linux_ip",
"port": $port
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "$my_real_linux_ws"
}
]
}
]
}
Start run in remote linux.
Add break points in vs code, and run -> start debugging, then hit an issue as follows. I am confused that test.py is not in dir /c4_working/test.py but in dir /c4_working/python_code/test.py. And this file actually exists. So I am not sure why it would want to find the file in dir /c4_working/test.py? How would I fix it?
Have you read the documentation before asking your question?
A specially this part:
PS: strongly recommend to check remote-pdb as well.
Fixed this issue after creating a new launch.json file for this dir /c4_working/python_code.

Why is my Vimspector debugging session not initializing?

I configured my vimspector.jsonfile and want to launch the debugger but when I do that it just says that it is initializing the debugger:
this is is my Vimspector.json:
{
"configurations": {
"test":{
"adapter": "vscode-python",
"configuration": {
"name": "this is a python test",
"type": "python",
"request": "launch",
"program":
"~/Documents/coding/python/terminal_game1/Terminal-Game/terminal_game.py"
}
}
}
}
Does anybody know what this means and how I can fix it?
Update:
After I've tried to use the debugpy-adapter the problem doesn't occur anymore and the debugger initializes correctly. But when trying to use the vscode-python adapter it still doesn't work even though I have installed its adapter via :VimspectorInstall vscode-python which ran successfully.
The adapter "vscode-python" is now declared legacy (No longer supported, please migrate your config), the supported adapter for python is now "debugpy".
so just replace vscode-python with debugpy in your .vimspector.json
This can be found on the plugin's Github page here.

Azure function Python - error "binding type(s) 'blobTrigger' are not registered"

I am trying to run an Azure function locally on my Mac and getting the following error: The binding type(s) 'blobTrigger' are not registered. Please ensure the type is correct and the binding extension is installed.
I'm working with Python 3.6.8 and have installed azure-functions-core-tools using homebrew (brew tap azure/functions; brew install azure-functions-core-tools).
Setup my local.settings.json file with the expected configuration, so function should be listening to the correct storage container hosted in azure.
Im certain I have not changed any code or configuration files since it was working last week.
host.json file contains:
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[1.*, 2.0.0)"
}
}
function.json file contains:
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "xmlblob",
"type": "blobTrigger",
"direction": "in",
"path": "<directory>/{name}",
"connection": "AzureStorageAccountConnectionString"
}
]
}
requirements.txt file contains:
azure-cosmos==3.1.0
azure-functions-worker==1.0.0b6
azure-storage==0.36.0
azure-storage-blob==2.0.1
xmljson==0.2.0
xmlschema==1.0.11
Then I run the following commands in my terminal:
1) pip install -r requirements.txt
2) source .env/bin/activate
3) func host start
I then get the following error:
<Application name>: The binding type(s) 'blobTrigger' are not registered. Please ensure the type is correct and the binding extension is installed.
You have done everything correct by the looks of it, but you need to have the dotnet core framework and runtime installed locally in order to execute the trigger.
For me on Ubuntu, I followed this guide. Once installed I was able to trigger a blob function locally.
For Mac, I would take a look here about installing dotnot core.
I got this error because there was something wrong with the bundle that it had downloaded and cached. In addition to the error message, earlier on in the log was a warning about not being able to load the Extension Bundle and a few lines earlier the log shows the path it's loading the bundle from, like C:\Users<redacted>\AppData\Local\Temp\Functions\ExtensionBundles\Microsoft.Azure.Functions.ExtensionBundle. I deleted the ExtensionBundles folder and it re-downloaded.
I followed nathan shumoogum solution that he describes in a comment on another answer of this question. It worked.
The process is:
Uninstall python dependencies, then python 3.6.8, uninstall azure-functions-core-tools and finally uninstall all versions of the .NET Core 2.2 SDK (in that order). Then reinstall everything in the reverse order for macOS.
Make sure you have the Microsoft.Azure.WebJobs.Extensions.Storage nuget package installed.
If you do it from portal , it prompted to install the extension.

Categories

Resources