Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change flask running port in VScode debugger

I do have a flask application running on port 8000 because i have logstash running on port 5000.

app.run(debug=True, host='0.0.0.0', port=8000)

i can run my app successfully. but when i use VScode debugger it throws

OSError: [Errno 98] Address already in use

because the debugger tries to run my app on port 5000. i tried editing .vscode/launch.json and set "port": 8000 inside configurations but the error still the same. how can i tell the VScode to run my app with debugger on another port?

like image 582
Sina Avatar asked Jul 16 '19 09:07

Sina


People also ask

How do I run a flask in debug mode Vscode?

If you click on the “Run and Debug” icon on the left hand side of the IDE or alternatively type Ctrl+Shift+D you will see the “RUN AND DEBUG” window. Now click on the “create a launch. json file” link and when prompted to “Select a debug configuration” choose “Python File Debug the currently active Python file”.

How do I change debug mode on flask?

If you're using the app. run() method instead of the flask run command, pass debug=True to enable debug mode. Tracebacks are also printed to the terminal running the server, regardless of development mode.


1 Answers

Add args key to your debug configuration and set the port there:

https://code.visualstudio.com/docs/python/debugging#_set-configuration-options

{
    "name": "Python: startup.py",
    "type": "python",
    "request": "launch",
    "program": "${workspaceFolder}/startup.py",
    "args" : ["run", "--port", "8000"]
}
like image 192
abdusco Avatar answered Sep 30 '22 19:09

abdusco