昨天我可以使用 VS Code 运行和调试我的 Azure Function 项目。今天,当我按下 F5(“开始调试”)时,会立即出现一个弹出窗口,其中显示
连接ECONNREFUSED 127.0.0.1:9091
我认为这是一个网络问题,因为 VS Code 甚至没有打开显示“正在执行任务 [...]”的终端。
但是在 VS Code 中我可以浏览扩展市场,在终端中运行“pip install”。
这是我的配置:
{
"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"
}
]
}
{
"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}"
}
}
]
}
{
"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": "&&"
}
这太奇怪了。我来回编辑了我的
launch.json
,有时是有效的,有时不是,现在当我保存原始 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"
}
]
}
我不确定我是否明白发生了什么事。
我也遇到了同样的问题,结果是一些权限问题,请参阅此处的答案
在 VS Code 终端或 Windows PowerShell 中写入:
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned
或
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Unrestricted
重新安装所有内容。
它有效。