when I run the following python code in run mode, the response equals 0, when I run it in debug mode, the response is 127 and the failure /bin/sh: ping: command not found occured.
cmd = '-c 1'
host = 192.168.1.1
response = subprocess.call(f'ping {cmd} {host}, shell=True')
my launch.json looks like that:
{
// 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: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
When using response = os.system(f'ping {cmd} {host}'), the response in run mode is 0 and in debug mode the response is 32512 and the failure sh: ping: command not found occured.
Can someone help me?
Related
I am new to azure function.
I want to run my azure function code locally (in an azure virtual machine).
I'm running my code using this line in a linux VM terminal:
. env/bin/activate && func host start
It was successful with this output.
Azure Functions Core Tools
Core Tools Version: 4.0.4785 Commit hash: N/A (64-bit)
Function Runtime Version: 4.10.4.19213
Functions:
update-info: [GET,POST] http://localhost:7071/update-info
However, I wonder if it is possible to change localhost:7071 to the IP of my virtual machine so that it will be available online. Is it? If yes, how?; if not, how can I run HTTPS request/response program in a VM?
Another question if it is possible is can I change it from http to https? If yes, how?
Edited: - Adding Settings from the config files.
function.json
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "$return"
}
]
}
host.json
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[2.*, 3.0.0)"
},
"extensions": {
"http": {
"routePrefix": ""
}
}
}
Btw, I already figured out how to run it using https. I had to add --useHTTPS on the command like this: . env/bin/activate && func host start --useHttps
I just need to know how to change the localhost to the VM IP address.
Created the Azure Linux VM > Hosted Azure Functions Python Project (Http Trigger Function) on it.
Enabled the Ports HTTP, HTTPS & RDP for checking using the browser by enabling the XRDP & installed the Firefox browser
Glad that enabling the HTTPS flag is resolved by yourself.
I'm able to get the Function App Result with the local host and private IP address in Azure Linux VM:
I want to run a node.js app from python. To run the node.js app in a terminal I type "npm start".
This is my package.json
{
"name": "web-scraping",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon app.js"
},
"author": "pupy frias",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"express-handlebars": "^5.3.3",
"nodemon": "^2.0.12",
"sqlite3": "^5.0.2"
}
}
I tried with os.system from python, but it didn't work.
So, tried with this
from subprocess import call
call(["node", "Offer Store\app.js"])
It worked, but don't find any files like views. When I run the app from any terminal (cmd, shell) it works, I don't know what is happening with this method. Please help me how to solve this issue. Thanks
Yesterday I could run and debug my Azure Function project with VS Code. Today, when I'm hitting F5 ("Start Debugging"), a pop-up instantly appears with
connect ECONNREFUSED 127.0.0.1:9091
I believe it's a network issue, since VS Code doesn't even open a terminal displaying "Executing task [...]".
But within VS Code I can browse the extension marketplace, run "pip install" within the terminal.
Here is my configuration:
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"
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "func",
"command": "host start",
"problemMatcher": "$func-python-watch",
"isBackground": true,
"dependsOn": "pipInstall",
"options": {
"cwd": "${config:azureFunctions.projectSubpath}"
}
},
{
"label": "pipInstall",
"type": "shell",
"command": "${config:python.pythonPath} -m pip install -r requirements.txt",
"problemMatcher": [],
"options": {
"cwd": "${config:azureFunctions.projectSubpath}"
}
}
]
}
settings.json
{
"azureFunctions.deploySubpath": "azure-functions\\my_project",
"azureFunctions.projectSubpath": "azure-functions\\my_project",
"azureFunctions.scmDoBuildDuringDeployment": true,
"azureFunctions.pythonVenv": ".venv",
"azureFunctions.projectLanguage": "Python",
"azureFunctions.projectRuntime": "~3",
"debug.internalConsoleOptions": "neverOpen",
"python.pythonPath": "C:\\Users\\myself\\BigRepo\\azure-functions\\my_project\\.venv\\Scripts\\python.exe",
"powershell.codeFormatting.addWhitespaceAroundPipe": true
//"terminal.integrated.shell.windows": "&&"
}
This is so weird. I edited my launch.json back and forth, sometimes it was a valid one, sometimes it was not, and now when I'm saving my original launch.json, the configuration works.
This configuration works fine:
{
"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"
}
]
}
I'm not sure I understand what is going on.
Re-install everything.
It works.
i'm following the query of the documentation of nginx unit with fastapi => https://unit.nginx.org/howto/fastapi/
I ran this query : curl -X PUT --data-binary #config.json --unix-socket /var/run/control.unit.sock http://localhost/config/
but i got an error :
"error": "Invalid configuration.",
"detail": "The module to run "python 3.8" is not found among the available application modules."
my config file (config.json) look like this :
{
"listeners": {
"*:80": {
"pass": "applications/fastapi"
}
},
"applications": {
"fastapi": {
"type": "python 3.8",
"path": "/home/ubuntu/inference1",
"home": "/home/ubuntu/anaconda3/envs/inference1/bin",
"module": "application",
"callable": "app"
}
}
}
the command line query i run to see the modules : ls /usr/lib/unit/modules
gives me :
java11.unit.so perl.unit.so python2.7.unit.so python3.7.unit.so ruby.unit.so
java8.unit.so php.unit.so python3.6.unit.so python3.8.unit.so
If someone knows why the query is returning me the error i cannot find it :'(
I need help in configuring my Vs code to run scripts in python using Cntrl Shift B, I was working fine until Vs code upgraded to version 2.0.0 now it wants me to configure the Build. And I am clueless what Build is all about.
In the past it worked well when I only needed to configure the task runner. There are youtube videos for the task runner. I cant seem to lay my finger on what the Build is all about.
In VS Code go Tasks -> Configure Tasks
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"taskName": "Run File",
"command": "python ${file}",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "always",
"panel": "new",
"focus": true
}
},
{
"taskName": "nosetest",
"command": "nosetests -v",
"type": "shell",
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"reveal": "always",
"panel": "new",
"focus": true
}
}
]
}
command: runs current python file
group: 'build'
presentation:
always shows the shell when run
uses a new shell
focuses the shell (i.e. keyboard is captured in shell window)
2nd Task is configured as the default test and just runs nosetest -v in the folder that's currently open in VS Code.
The "Run Build Task" (the one that's bound to Ctrl+Shift+B) is the one that's configured as the default build task, task 1 in this example (see the group entry).
EDIT:
Suggested by #RafaelZayas in the comments (this will use the Python interpreter that's specified in VS Code's settings rather than the system default; see his comment for more info):
"command": "${command:python.interpreterPath} ${file}"
...Don't have enough reputation to comment on the accepted answer...
At least in my environment (Ubuntu 18.04, w/ virtual env) if arguments are being passed in with "args", the file must be the first argument, as #VladBezden is doing, and not part of the command as #orangeInk is doing. Otherwise I get the message "No such file or directory".
Specifically, the answer #VladBezden has does work for me, where the following does not.
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "${config:python.pythonPath} setup.py", // WRONG, move setup.py to args
"group": {
"kind": "build",
"isDefault": true
},
"args": [
"install"
],
"presentation": {
"echo": true,
"panel": "shared",
"focus": true
}
}
]
}
This took me a while to figure out, so I thought I would share.
Here is my configuration for the build (Ctrl+Shift+B)
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "python",
"group": {
"kind": "build",
"isDefault": true
},
"args": [
"setup.py",
"install"
],
"presentation": {
"echo": true,
"panel": "shared",
"focus": true
}
}
]
}