Skip to content

Attaching using PEP 768 style code injection fails when there's a backslash in the temp path #2037

Closed

Description

When attempting to attach using PEP 768 style code injection, the code written to the temp file contains invalid characters if the temp file path contains backslashes (such as "C:\Users\xxx\AppData\Local\Temp\")

"""import os;os.remove("{tmp_file_path}");""".format(

This results in an error when the code is attempted to be run:

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape (<string>, line 1)

It looks like this was introduced in c7e86a1. The fix would be to escape the path on Windows when writing the file, or simply replace backslashes with forward slashes.

Environment data

  • debugpy version: 1.8.20
  • OS and version: Windows 11
  • Python version: 3.14.5
  • Using VS Code or Visual Studio: VS Code

Actual behavior

Attempting to attach to a Python 3.14 process on Windows where the temp folder has a "\" in the path fails with the error

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape (<string>, line 1)

Expected behavior

It should attach to the process.

Steps to reproduce:

  1. Start a Python 3.14 process on Windows
  2. Attempt to attach to it using VS Code

Activity

  1. rchiodo commented on Jun 15, 2026

    @rchiodo
    Contributor

    Yeah this just breaks debugging altogether. I thought it would just force pydevd to be used.

    Here's my output after debugging fails:

    :\Users\rchiodo\source\testing\docstring_parser>C:\Users\rchiodo\AppData\Local\Programs\Python\Python314\python.exe test_attach.py
    PID: 21804
    Enter somethingx
    Error executing debugger script C:\Users\rchiodo\AppData\Local\Temp\tmp0_vuee4s:
    Traceback (most recent call last):
    File "C:\Users\rchiodo\source\testing\docstring_parser\test_attach.py", line 5, in
    x = input("Enter something")
    SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape (, line 1)
    x

  2. added a commit that references this issue on Jun 15, 2026
    9901bd9
  3. added a commit that references this issue on Jun 15, 2026
    8122aaa
  4. added a commit that references this issue on Jun 15, 2026
    51f0f80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions