[Python] Flask doesn't claim any port [duplicate]

Discussão em 'Python' iniciado por Stack, Janeiro 23, 2025.

  1. Stack

    Stack Membro Participativo

    Been writing some code, used flask in debug mode to test html etc which worked fine on http://127.0.0.1:5000. But I ran into in issue in the Python code that I couldn't get resolved with just print statements of what values some variables had. I really needed to be able to debug the python code line by line.

    Tried some configuration changes in VScode but didn't get debugging to run, but worse, the "normal" flask debugging mode isn't claiming a port anymore.

    Usually in VScode after starting the app.py, I see flask starting and saying it is now available at http://127.0.0.1:5000 and in the "Ports" window, I see port 5000 in use. But it doesn't do that anymore.

    I changed something in the python - flask debugger 'launcher.json', but not sure what the original config was. I used to check the webpage with chrome, but that now gives me an error: Access to 127.0.0.1 was denied You don't have authorisation to view this page. HTTP ERROR 403 even when trying incognito mode. Firefox just shows an empty page.

    app.py:

    <snip some imports>
    @app.route("/")
    def index():
    return render_template("index.html")

    if __name__ == "__main__":
    app.run(debug=True)


    Also tried

    app.run(host="127.0.0.1",port=5000,debug=True)
    app.run(host="0.0.0.0",port=5000,debug=True)


    launch.json:

    {
    "version": "0.2.0",
    "configurations": [
    {
    "name": "Python Debugger: Flask",
    "type": "debugpy",
    "request": "launch",
    "module": "flask",
    "env": {
    "FLASK_APP": "app.py",
    "FLASK_DEBUG": "1"
    },
    "args": [
    "run",
    "--no-debugger",
    "--no-reload"
    ],
    "jinja": true,
    "autoStartBrowser": false
    },
    {
    "name": "Python Debugger: Python File",
    "type": "debugpy",
    "request": "launch",
    "program": "${file}"
    }
    ]
    }


    When the app is started, the terminal window shows:

    • Tip: There are .env files present. Install python-dotenv to use them.
    • Serving Flask app 'app'
    • Debug mode: on

    Continue reading...

Compartilhe esta Página