Skip to content

Debugger fails to start due to socket connection error #2537

Closed

Description

@zhaoyewei

Environment data

  • VS Code version: 1.27.1
  • Extension version (available under the Extensions sidebar):
    C/C++
    Code Runner
    Python
    VIM
  • OS and version: win10 64bit
  • Python version (& distribution if applicable, e.g. Anaconda): 3.6.3
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): conda
  • Relevant/affected Python packages and their versions: N/A

Actual behavior

cd 'e:\Code\Python'; ${env:PYTHONPATH}='temp;c:\Users\zhao\.vscode\extensions\ms-python.python-2018.8.0\pythonFiles\experimental\ptvsd'; ${env:PYTHONIOENCODING}='UTF-8'; ${env:PYTHONUNBUFFERED}='1'; & 'D:\Anaconda\python.exe' '-m' 'ptvsd' '--host' 'localhost' '--port' '51495' 'e:\Code\Python\test.py'
Output:

Could not connect to localhost: 51495
Traceback (most recent call last):
  File "c:\Users\zhao\.vscode\extensions\ms-python.python-2018.8.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\pydevd.py", line 1743, in main
    debugger.connect(host, port)
  File "c:\Users\zhao\.vscode\extensions\ms-python.python-2018.8.0\pythonFiles\experimental\ptvsd\ptvsd\_vendored\pydevd\pydevd.py", line 349, in connect
    s = start_client(host, port)
  File "c:\Users\zhao\.vscode\extensions\ms-python.python-2018.8.0\pythonFiles\experimental\ptvsd\ptvsd\pydevd_hooks.py", line 81, in <lambda>
    _start_client = (lambda h, p: start_client(daemon, h, p))
  File "c:\Users\zhao\.vscode\extensions\ms-python.python-2018.8.0\pythonFiles\experimental\ptvsd\ptvsd\pydevd_hooks.py", line 61, in start_client
    sock, start_session = daemon.start_client((host, port))
  File "c:\Users\zhao\.vscode\extensions\ms-python.python-2018.8.0\pythonFiles\experimental\ptvsd\ptvsd\daemon.py", line 203, in start_client
    connect(client, addr)
  File "c:\Users\zhao\.vscode\extensions\ms-python.python-2018.8.0\pythonFiles\experimental\ptvsd\ptvsd\socket.py", line 174, in connect
    sock.connect(addr)
TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。

Expected behavior

Noramlly Debugg Current file

Logs

Nothing.

I can't Debug My python code.
Everytime if press F5,Termianl will execute
cd 'e:\Code\Python'; ${env:PYTHONPATH}='temp;c:\Users\MYUSERNAME\.vscode\extensions\ms-python.python-2018.8.0\pythonFiles\experimental\ptvsd'; ${env:PYTHONIOENCODING}='UTF-8'; ${env:PYTHONUNBUFFERED}='1'; & 'D:\Anaconda\python.exe '-m' 'ptvsd' '--host' 'localhost' '--port' '51495' file.py",
then fail.
I tried uinstall python extension,but fail still.
What's wrong?

this is my launch.json:

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File (Integrated Terminal)",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        },
        {
            "name": "Python: Attach",
            "type": "python",
            "request": "attach",
            "port": 5678,
            "host": "localhost"
        },
        {
            "name": "Python: Django",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/manage.py",
            "console": "integratedTerminal",
            "args": [
                "runserver",
                "--noreload",
                "--nothreading"
            ],
            "django": true
        },
        {
            "name": "Python: Flask",
            "type": "python",
            "request": "launch",
            "module": "flask",
            "env": {
                "FLASK_APP": "app.py"
            },
            "args": [
                "run",
                "--no-debugger",
                "--no-reload"
            ],
            "jinja": true
        },
        {
            "name": "Python: Current File (External Terminal)",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "externalTerminal"
        }
    ]
}

My python path is system settings:
D:/anaconda/python.exe

Activity

  1. brettcannon commented on Sep 10, 2018

    @brettcannon
    Member

    FYI the translation of the WinError is "The connection attempt failed because the connected party did not respond correctly after a period of time or the connected host did not respond.".

    Does D:\Anaconda\python.exe e:\Code\Python\test.py work from the terminal?

  2. added
    bug
    info-needed
    on Sep 10, 2018
  3. zhaoyewei commented on Sep 11, 2018

    @zhaoyewei
    Author

    Brett Cannon (@brettcannon) Yes,it works as expected. python file is ran properly.
    Whatever i edit launch.json,the command line executed in termianl harly change.
    One thing i don't konw is that why i try to debug py file locally,there is alway
    '-m' 'ptvsd' '--host' 'localhost' '--port' '51495'
    displayed in termianl but always connecto to localhost fail.(Port is not stable)

  4. groeneveld commented on Sep 11, 2018

    @groeneveld
  5. added and removed
    info-needed
    on Sep 11, 2018
  6. DonJayamanne commented on Sep 12, 2018

    @DonJayamanne
  7. changed the title [-]Debugger Always Error[/-] on Sep 12, 2018
  8. DonJayamanne commented on Sep 12, 2018

    @DonJayamanne

    ZhaoTongxue
    Please could you try to start a simple socket server in Python and connecting to it

    Here's some sample code:

    • Run socket_server.py in a terminal
    • Then run socket_client.py in a terminal

    socket_server.py

    import socket
     
    def Main():
        host = "localhost"
        port = 51495
         
        mySocket = socket.socket()
        mySocket.bind((host,port))
         
        mySocket.listen(1)
        conn, addr = mySocket.accept()
        print ("Connection from: " + str(addr))
        while True:
                data = conn.recv(1024).decode()
                if not data:
                        break
                print ("from connected  user: " + str(data))
                 
                data = str(data).upper()
                print ("sending: " + str(data))
                conn.send(data.encode())
                 
        conn.close()
         
    if __name__ == '__main__':
        Main()

    socket_client.py

    import socket
     
    def Main():
        host = "localhost"
        port = 51495
         
        mySocket = socket.socket()
        mySocket.bind((host,port))
         
        mySocket.listen(1)
        conn, addr = mySocket.accept()
        print ("Connection from: " + str(addr))
        while True:
                data = conn.recv(1024).decode()
                if not data:
                        break
                print ("from connected  user: " + str(data))
                 
                data = str(data).upper()
                print ("sending: " + str(data))
                conn.send(data.encode())
                 
        conn.close()
         
    if __name__ == '__main__':
        Main()
  9. added
    info-needed
    and removed on Sep 12, 2018
  10. zhaoyewei commented on Sep 13, 2018

    @zhaoyewei
    Author

    Don Jayamanne (@DonJayamanne) Thanks,and i do what you say.(PS:your socket_client.py is the same as socket_server.py,may you have paste a false copy😂)
    I ran socket_server.py and then i ran a python file which is function as client to test socket,as a result,and successed.
    there is my socket_client.py:

    def Main():
        host="localhost"
        port=51495
        mySocket=socket.socket()
        mySocket.connect((host,port))
        mySocket.send("I am client".encode())
        response=mySocket.recv(1024)
        print("response:\n",response.decode())
        mySocket.close()
    if __name__=="__main__":
        Main()
    

    There is what socket_server.py print out:

    Connection from: ('127.0.0.1', 17759)
    from connected user: I am client
    sending: I AM CLIENT

    There is what my client socket file print out:

    response:
    I AM CLIENT

    when i debug my pytho file in vscode,i don't know whether the port is open.

  11. zhaoyewei commented on Sep 13, 2018

    @zhaoyewei
    Author

    Plus,In my .vscode/launch.json,"debugOptions" are not support by intelligense and linting.Even after serveral tries,it doesn't improve.

  12. DonJayamanne commented on Sep 13, 2018

    @DonJayamanne

    Even after serveral tries,it doesn't improve.

    1. Please delete your launch.json file and re-create it.
    2. Please go into your launch.json and add the setting "logToFile": true
    3. Start debugging
    4. Once complete (even after a failure), go into VS Code and select the command Extensions: Open Extensions Folder
    5. Locate the python extensions directory ms-python.python-2018-**
    6. Look for a file named debug.log, please upload that file here
  13. zhaoyewei commented on Sep 14, 2018

    @zhaoyewei
    Author

    Don Jayamanne (@DonJayamanne) thanks, i tired.
    The file was uploaded as appendix.
    debug.log

  14. DonJayamanne commented on Sep 14, 2018

    @DonJayamanne

    ZhaoTongxue
    Please could you install the development version of the extension from here and give that a try. (https://github.com/Microsoft/vscode-python/blob/master/CONTRIBUTING.md#development-build)

  15. zhaoyewei commented on Sep 15, 2018

    @zhaoyewei
    Author

    I uninstalled vscode-python sand installed developmemt version of the extension,however,ail again.There is debug.log.

    `10:29:41 AM, 9/15/2018
    Started @ Sat Sep 15 2018 10:29:41 GMT+0800 (中国标准时间)
    From Client:
    Content-Length: 313
    
    {"command":"initialize","arguments":{"clientID":"vscode","clientName":"Visual Studio Code","adapterID":"python","pathFormat":"path","linesStartAt1":true,"columnsStartAt1":true,"supportsVariableType":true,"supportsVariablePaging":true,"supportsRunInTerminalRequest":true,"locale":"zh-cn"},"type":"request","seq":1}
    To Client:
    Content-Length: 653
    
    {"seq":1,"type":"response","request_seq":1,"command":"initialize","success":true,"body":{"supportsExceptionInfoRequest":true,"supportsConfigurationDoneRequest":true,"supportsConditionalBreakpoints":true,"supportsSetVariable":true,"supportsExceptionOptions":true,"supportsEvaluateForHovers":true,"supportsModulesRequest":true,"supportsValueFormattingOptions":true,"supportsHitConditionalBreakpoints":true,"supportsSetExpression":true,"supportsLogPoints":true,"supportTerminateDebuggee":true,"exceptionBreakpointFilters":[{"filter":"raised","label":"Raised Exceptions","default":false},{"filter":"uncaught","label":"Uncaught Exceptions","default":true}]}}
    From Client:
    Content-Length: 494
    
    {"command":"launch","arguments":{"name":"Python: Current File (Integrated Terminal)","type":"python","request":"launch","program":"e:\\Code\\Python\\test.py","console":"integratedTerminal","logToFile":true,"pythonPath":"D:\\Anaconda\\python.exe","cwd":"e:\\Code\\Python","envFile":"e:\\Code\\Python\\.env","stopOnEntry":false,"internalConsoleOptions":"neverOpen","debugOptions":["RedirectOutput","FixFilePathCase"],"__sessionId":"b81f5e17-6bd8-4fc9-8360-da446ce078ac"},"type":"request","seq":2}
    To Client:
    Content-Length: 390
    
    {"command":"runInTerminal","arguments":{"kind":"integrated","title":"Python Debug Console","cwd":"e:\\Code\\Python","args":["D:\\Anaconda\\python.exe","c:\\Users\\zhao\\.vscode\\extensions\\ms-python.python-2018.9.0-alpha\\pythonFiles\\experimental\\ptvsd_launcher.py","19031","e:\\Code\\Python\\test.py"],"env":{"PYTHONIOENCODING":"UTF-8","PYTHONUNBUFFERED":"1"}},"type":"request","seq":2}
    From Client:
    Content-Length: 94
    
    {"type":"response","seq":3,"command":"runInTerminal","request_seq":2,"success":true,"body":{}}
    To Client:
    Content-Length: 207
    
    {"seq":3,"type":"response","request_seq":2,"command":"launch","success":false,"message":"Timeout waiting for debugger connection","body":{"error":{"format":"Timeout waiting for debugger connection","id":1}}}
    From Client:
    Content-Length: 79
    
    {"command":"disconnect","arguments":{"restart":false},"type":"request","seq":4}
    onResponseDisconnect
    To Client:
    Content-Length: 81
    
    {"seq":4,"type":"response","request_seq":4,"command":"disconnect","success":true}
    check and shutdown
    `
    

    I am confused by this situation🤔

  16. zhaoyewei commented on Sep 15, 2018

    @zhaoyewei
    Author

    there is even no "debugOptions" displayed in intelligense.
    image
    The same as stable version.

  17. zhaoyewei commented on Sep 15, 2018

    @zhaoyewei
    Author

    But,,after i update anaconda and reinstall vscode-python stable.It works😳
    what,,what happened....

  18. locked as resolved and limited conversation to collaborators on Oct 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-debuggingbuginfo-needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions