我想在VS Code中开发一个HttpTrigger函数,但每次尝试运行和调试时,我都会收到以下错误消息:
连接econnrejected 127.0.0.1:9091
我尝试了很多详细的解决方案,但没有一个工作。以下是我的配置信息:
- VS代码:1.79.0
- 简体中文(zh_cn)
- Azure功能核心工具:4.0.5198
- Windows 10专业版
以下是我的文件信息:
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
这是因为它是生成的,我不改变任何东西,它仍然不工作。
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
)
当我使用run & debug时,我得到了这个:
当我使用命令行来启动函数时,我得到这样的结果:
还有更多的MS_FUNCTION行,但我认为它们没有用。如果有人知道我怎么能删除这些指纹,我会很感激,因为没有人有那些当我在寻找答案。我尝试的列表:
- 将端口更改为7071或9092
- 描述的3种可能性here
- 我在powershell.exe上设置了“terminal.integrated.shell.windows”
- 卸载VS Code、Azure Functions Core Tools和Python,但没有用
1条答案
按热度按时间qvk1mo1f1#
我也用了同样的版本--
init. py