I wanted to debug my local Python
code as usual in VS-Code
on Windows 10
via pressing F5
:
I started having this error already more than a year ago, but recently it became persistent.
The entire error traceback:
$ /usr/bin/env 'DEBUGPY_LOG_DIR=c:\Users\username\.vscode\extensions\ms-python.python-2021.8.1105858891' c:\\Users\\username\\Projects\\project-venv\\Scripts\\python.exe c:\\Users\\username\\.vscode\\extensions\\ms-python.python-2021.8.1105858891\\pythonFiles\\lib\\python\\debugpy\\launcher 56721 -- c:\\Users\\username\\Projects\\project\\test_files\\prediction_performance_monitoring\\modified_app_for_docker_testing.py
Traceback (most recent call last):
File "C:\Users\username\.pyenv\pyenv-win\versions\3.8.9\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\username\.pyenv\pyenv-win\versions\3.8.9\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "c:\Users\username\.vscode\extensions\ms-python.python-2021.8.1105858891\pythonFiles\lib\python\debugpy\launcher\__main__.py", line 97, in
<module>
main()
File "c:\Users\username\.vscode\extensions\ms-python.python-2021.8.1105858891\pythonFiles\lib\python\debugpy\launcher\__main__.py", line 53, in
main
launcher.connect(host, port)
File "c:\Users\username\.vscode\extensions\ms-python.python-2021.8.1105858891\pythonFiles\lib\python\debugpy\launcher/../..\debugpy\launcher\__init__.py", line 34, in connect
sock.connect((host, port))
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
The .vscode/launch.json
debugging configuration for local file testing contains these settings:
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File (Integrated Terminal)",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"python": "C:\\Users\\andreas.luckert\\Projects\\project-venv\\Scripts\\python.exe",
"redirectOutput": true,
"justMyCode": false,
"logToFile": true,
"stopOnEntry": false,
}
]
}
Searching for the issue on StackOverFlow there were similar questions, but the answers (similar issue here) mostly stated something akin to
WinError 10061 - means that the server side TCP is not accepting the connection. For there is no application above listening on that port that client is trying to connect. Please check if you have your server application started and that it is listening on the intended port.
Yet, this did not help me because the questions referred to some remote connection, but in my case the debugging process is conducted locally. Moreover, I have not changed anything in the above-mentioned configuration which had been working normally a week ago.
Other answers like here included firewall diffulties, e.g.
Is firewall running on the server? If so, that may be blocking connections. You could disable firewall or add an exception on the server side to allow connections on port 8000.
I could not figure out how my firewall should block this debugging process, especially because it was not a constant issue but came and went irregularly. At times I thought it was related to a temporary shortage of free RAM, but this was proven a false assumption.
By and large, I cannot work sensibly with VS-Code Python debugging
anymore. As this is an integral part of my workflow, I need to find out how to get rid of this problem.