Following the instructions in (https://code.visualstudio.com/docs/python/tutorial-flask) to run the code in vscode debugger throws the error:
Error: Failed to find Flask application or factory in module "app". Use "FLASK_APP=app:name to specify one.
The reason in that the app is created by:
app = connexion.FlaskApp(__name__)
instead of:
app = Flask(__name__)
So the FLASK_APP could not be recognized.
Is there a workaround for this to enable debugging in vscode?
Same problem for me. Any idea?
Can you post the your launch.json file? I suspect the FLASK_APP value starts with "{workspaceFolder}...".
NOTE: I've been at this a while and still have not successfully been able to debug a Flask/Connexion app in VSCode, but I have made it past the error you posted.
Add this config profile to the workspace .vscode/launch.json:
{
"name": "Python: Connexion",
"type": "python",
"request": "launch",
"module": "connexion",
"cwd": "${workspaceFolder}",
"env": {
...
},
"args": [
"run",
"[SPEC_DIR]/[SPEC_FILE]",
"--port",
"[HTTP_PORT]"
]
}
That launch config works for me.
Most helpful comment
Add this config profile to the workspace .vscode/launch.json: