2

I've started remote debugging with visual studio code but I cant get it to work. Both the remote and the local development PC both running version 4.1.3 of ptvsd. The remote machine has the script :

import ptvsd
ptvsd.enable_attach()

#Enable the below line of code only if you want the application to wait untill the debugger has att$
#ptvsd.wait_for_attach()

import random


guesses_made = 0
name = input('Hello! What is your name?\n')
number = random.randint(1, 20)
print('Well, {0}, I am thinking of a number between 1 and 20.'.format(name))

while guesses_made < 6:
    guess = int(input('Take a guess: '))
    guesses_made += 1
    if guess < number:
        print('Your guess is too low.')
    if guess > number:
        print('Your guess is too high.')
    if guess == number:
        break
if guess == number:
    print('Good job, {0}! You guessed my number in {1} guesses!'.format(name, guesses_made))
else:
    print('Nope. The number I was thinking of was {0}'.format(number))

The local computer is :

import ptvsd
ptvsd.enable_attach(address = ('192.34.98.197',3000))

#Enable the below line of code only if you want the application to wait untill the debugger has attached to it
#ptvsd.wait_for_attach()

import random

guesses_made = 0
name = input('Hello! What is your name?\n')
number = random.randint(1, 20)
print('Well, {0}, I am thinking of a number between 1 and 20.'.format(name))

while guesses_made < 6:
    guess = int(input('Take a guess: '))
    guesses_made += 1
    if guess < number:
        print('Your guess is too low.')
    if guess > number:
        print('Your guess is too high.')
    if guess == number:
        break
if guess == number:
    print('Good job, {0}! You guessed my number in {1} guesses!'.format(name, guesses_made))
else:
    print('Nope. The number I was thinking of was {0}'.format(number))

I've added the entries into launch.json :

{
    "name": "Attach (Remote Debug)",
    "type": "python",
    "request": "attach",
    "localRoot": "${workspaceRoot}",
    "remoteRoot": "/home/pi/testdebug/",
    "port": 3000,
    "secret": "my_secret",
    "host":"localhost"
},

This is the error i receive:

> PS C:\IOT\Github\RaspberryPi\test_remote_debug> python
> .\test_remote_debug.py Traceback (most recent call last):   File
> ".\test_remote_debug.py", line 2, in <module>
>     ptvsd.enable_attach(address = ('192.34.98.197',3000))   File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\attach_server.py", line 72,
> in enable_attach
>     redirect_output=redirect_output,   File "C:\Program Files (x86)\Python37-32\lib\site-packages\ptvsd\_remote.py", line 85, in
> enable_attach
>     suspend=False)   File "C:\Program Files (x86)\Python37-32\lib\site-packages\ptvsd\_vendored\pydevd\pydevd.py",
> line 1313, in settrace
>     stop_at_frame,   File "C:\Program Files (x86)\Python37-32\lib\site-packages\ptvsd\_vendored\pydevd\pydevd.py",
> line 1362, in _locked_settrace
>     debugger.connect(host, port)  # Note: connect can raise error.   File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\_vendored\pydevd\pydevd.py",
> line 355, in connect
>     s = start_client(host, port)   File "C:\Program Files (x86)\Python37-32\lib\site-packages\ptvsd\pydevd_hooks.py", line 85,
> in <lambda>
>     _start_client = (lambda h, p: start_client(daemon, h, p))   File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\_remote.py", line 72, in
> <lambda>
>     start_client=(lambda daemon, h, port: start_daemon()),   File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\_remote.py", line 64, in
> start_daemon
>     _, next_session = daemon.start_server(addr=(host, port))   File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\daemon.py", line 157, in
> start_server
>     self._server = create_server(addr.host, addr.port)   File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\socket.py", line 77, in
> create_server
>     server.bind((host, port)) OSError: [WinError 10049] The requested address is not valid in its context PS
> C:\IOT\Github\RaspberryPi\test_remote_debug> python
> .\test_remote_debug.py Traceback (most recent call last):   File
> ".\test_remote_debug.py", line 2, in <module>
>     ptvsd.enable_attach(address = ('192.34.98.197',3000))   File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\attach_server.py", line 72,
> in enable_attach
>     redirect_output=redirect_output,   File "C:\Program Files (x86)\Python37-32\lib\site-packages\ptvsd\_remote.py", line 85, in
> enable_attach
>     suspend=False)   File "C:\Program Files (x86)\Python37-32\lib\site-packages\ptvsd\_vendored\pydevd\pydevd.py",
> line 1313, in settrace
>     stop_at_frame,   File "C:\Program Files (x86)\Python37-32\lib\site-packages\ptvsd\_vendored\pydevd\pydevd.py",
> line 1362, in _locked_settrace
>     debugger.connect(host, port)  # Note: connect can raise error.   File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\_vendored\pydevd\pydevd.py",
> line 355, in connect
>     s = start_client(host, port)   File "C:\Program Files (x86)\Python37-32\lib\site-packages\ptvsd\pydevd_hooks.py", line 85,
> in <lambda>
>     _start_client = (lambda h, p: start_client(daemon, h, p))   File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\_remote.py", line 72, in
> <lambda>
>     start_client=(lambda daemon, h, port: start_daemon()),   File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\_remote.py", line 64, in
> start_daemon
>     _, next_session = daemon.start_server(addr=(host, port))   File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\daemon.py", line 157, in
> start_server
>     self._server = create_server(addr.host, addr.port)   File "C:\Program Files
> (x86)\Python37-32\lib\site-packages\ptvsd\socket.py", line 77, in
> create_server
>     server.bind((host, port)) OSError: [WinError 10049] The requested address is not valid in its context

If anyone has any ideas how to correct this please let me know.

1 Answer 1

2

Your launch.json is out-of-date as it's configured for the old debugger. Please see https://code.visualstudio.com/docs/python/debugging#_remote-debugging for the latest instructions (e.g. localRoot and remoteRoote should be under pathMappings).

Sign up to request clarification or add additional context in comments.

3 Comments

Brilliant a step closer, im now getting the local and remote computer to talk to each other. im getting the following message twice : pydev debugger: warning: trying to add breakpoint to file that does not exist: /home/pi/testdebug/C:/IOT/Github/RaspberryPi/test_remote_debug/test_remote_debug.py (will have no effect). Any ideas why?
p.s. I've created another questions at as its a different question: stackoverflow.com/questions/52760636/…
Your paths don't look set up appropriately for localRoot and remoteRoot. If you look at /home/pi/testdebug/C:/IOT/Github/RaspberryPi/test_remote_debug/test_remote_debug.py you will notice that you seem to have some UNIX path prepended to a Windows path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.