How to use debugpy in VScode to debug remote python server?

811 Views Asked by At

I've used "type": "python" to debug remote python servers. Now I'm seeing this warning in launch.json:

This configuration will be deprecated soon. Please replace python with debugpy to use the new Python Debugger extension.

enter image description here

My original setting:

{
      "type": "python",
      "request": "attach",
      "name": "attach remote",
      "host": "192.168.1.101",
      "port": 8765,
      "pathMappings": [
        {
          "localRoot": "${workspaceFolder}/...",
          "remoteRoot": "/usr/app/..."
        }
      ],
      "justMyCode": false
    },

When I switch to "type": "debugpy" I get the following error on the "port" and "host" fields:

Property port is not allowed.

enter image description here

So the question is: how to add the port and host information to complete the migration of the debug configuration?

1

There are 1 best solutions below

0
PeterKogan On

So it turns out it's pretty easy: replace the "port" and "host" attributes with "connect", so if your configuration was:

{
      "type": "python",
      "request": "attach",
      "name": "attach remote",
      "host": "192.168.1.101",
      "port": 8765,
      "pathMappings": [
        {
          "localRoot": "${workspaceFolder}/...",
          "remoteRoot": "/usr/app/..."
        }
      ],
      "justMyCode": false
    },

It becomes:

{
      "type": "debugpy",
      "request": "attach",
      "name": "attach remote",
      "connect": { "host": "192.168.1.101", "port": 8765 },
      "pathMappings": [
        {
          "localRoot": "${workspaceFolder}/...",
          "remoteRoot": "/usr/app/..."
        }
      ],
      "justMyCode": false
    },