pythonvisual-studio-codedebuggingdebugpy

Debugpy Connection Refused Debug in VsCode


Good morning. Since yesterday I can't seem to connect to my debugger using debugpy. I'm getting a ECONNREFUSED error, I haven't really changed anything and can't seem to connect to my debugger. Debugpy starts listening to the port, but vscode can't connect to it.

This is my debugpy script:

import os
import debugpy
os.environ['PYDEVD_DISABLE_FILE_VALIDATION'] = '1'
if os.environ.get('DEBUG','false').lower().strip() == 'true':
    debugpy.listen(("localhost", 5678))
    print("Waiting for debugger attach on port 5678...")
    debugpy.wait_for_client()
    print("Debugger attached!")

This is my Vscode launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Serverless Debug",
      "type": "python",
      "request": "attach",
      "port": 5678,
      "host": "localhost",
      "console": "integratedTerminal",
      "pathMappings": [
        {
          "localRoot": "${workspaceFolder}",
          "remoteRoot": "."
        }
      ]
      // ,
      // "pythonArgs": [
      //   "-Xfrozen_modules=off"
      // ]
    }
  ]
}

also tried this:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Serverless Debug",
      "type": "debugpy",
      "request": "attach",
      "connect": {
        "host": "localhost",
        "port": 5678
      },
      "pathMappings": [
        {
          "localRoot": "${workspaceFolder}",
          "remoteRoot": "."
        }
      ]
    }
  ]
}

Has anyone else experienced this?


Solution

  • It was a bug on Debugpy or VsCode, the last updates have fixed the problem.