Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Setting breakpoint fails on Python files containing non-ASCII characters #1037

Closed
DonJayamanne opened this issue Nov 19, 2018 · 2 comments
Closed
Assignees
Labels

Comments

@DonJayamanne
Copy link
Contributor

Original issue can be found here microsoft/vscode-python#2914

@karthiknadig
Copy link
Member

This is a 2.7 unicode file path issue. Relevant stack where this breaks:

C:\Users\Administrator\Desktop\项目源代码\unetfe-rotation>cd c:\Users\Administrator\Desktop\项目源代码\unetfe-rotation && cmd /C "set "PYTHONIOENCODING=UTF-8" && set "PYTHONUNBUFFERED=1" && python c:\Users\Administrator\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd_launcher.py 53714 c:\Users\Administrator\Desktop\项目源代码\unetfe-rotation\app.py "
Traceback (most recent call last):
  File "c:\Users\Administrator\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\wrapper.py", line 1292, in done
    fut.result()
  File "c:\Users\Administrator\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\futures.py", line 40, in result
    reraise(self._exc_info)
  File "c:\Users\Administrator\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\futures.py", line 149, in callback
    x = next(it)
  File "c:\Users\Administrator\.vscode\extensions\ms-python.python-2018.9.0\pythonFiles\experimental\ptvsd\ptvsd\wrapper.py", line 2123, in on_setBreakpoints
    msg = '{}\t{}\t{}'.format(bp_type, path, vsc_bpid)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 31-35: ordinal not in range(128)

We have a test, test_path_with_unicode this is disabled in 2.7, we should enable it after this is fixed.

@int19h
Copy link
Contributor

int19h commented Nov 19, 2018

The reason why this fails is because sys.getdefaultencoding() is ascii on Windows (regardless of locale), and that's what's used by implicit str<->unicode conversion in 2.7. In this case, path is actually unicode, but we're trying to convert to str because the string literal on the left is doesn't have the u prefix.

So far as I can see, just using u'...' form for the literal should fix this. We should probably do this for all places that format messages to sent to pydevd, anywhere in wrapper.py - basically any string that goes to pydevd_notify should be created as unicode (we can add an assert to that method to find all such places). The implementation of pydevd_notify already does proper encoding to bytes before sending it over.

@int19h int19h changed the title Setting breakpoint fails on Python files containing ascii characters Setting breakpoint fails on Python files containing non-ASCII characters Dec 6, 2018
@int19h int19h self-assigned this Dec 6, 2018
int19h added a commit to int19h/ptvsd that referenced this issue Dec 6, 2018
…ng non-ASCII characters

Fix microsoft#1066: Fetching remote source for a file with a Unicode name fails on 2.7
int19h added a commit that referenced this issue Dec 7, 2018
…CII characters (#1068)

Fix #1066: Fetching remote source for a file with a Unicode name fails on 2.7
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants