Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 #306

Open
artofhuman opened this issue Jan 31, 2024 · 10 comments
Open

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 #306

artofhuman opened this issue Jan 31, 2024 · 10 comments

Comments

@artofhuman
Copy link

Hi. I have the error after start LSP.

LSP-pyright: INFO: poetry.lock detected. Run subprocess command: poetry env info -p
Unable to start subprocess for LSP-pyright
Traceback (most recent call last):
  File "/Users/semyonpupkov/Library/Application Support/Sublime Text/Installed Packages/LSP.sublime-package/plugin/core/windows.py", line 265, in start_async
    cwd = plugin_class.on_pre_start(self._window, initiating_view, workspace_folders, config)
  File "/Users/semyonpupkov/Library/Application Support/Sublime Text/Installed Packages/LSP-pyright.sublime-package/plugin.py", line 75, in on_pre_start
    python_path = cls.python_path(configuration.settings, workspace_folders)
  File "/Users/semyonpupkov/Library/Application Support/Sublime Text/Installed Packages/LSP-pyright.sublime-package/plugin.py", line 199, in python_path
    python_path = cls.python_path_from_venv(workspace_folder)
  File "/Users/semyonpupkov/Library/Application Support/Sublime Text/Installed Packages/LSP-pyright.sublime-package/plugin.py", line 247, in python_path_from_venv
    universal_newlines=True,
  File "./python3.3/subprocess.py", line 578, in check_output
  File "./python3.3/subprocess.py", line 907, in communicate
  File "./python3.3/subprocess.py", line 479, in _eintr_retry_call
  File "./python3.3/encodings/ascii.py", line 26, in decode
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 547: ordinal not in range(128)
@rchl
Copy link
Member

rchl commented Jan 31, 2024

What output are you getting when running poetry env info -p in the terminal, in that workspace?

@artofhuman
Copy link
Author

poetry env info -p        
Warning: Found deprecated key 'default' or 'secondary' in pyproject.toml configuration for source kontur. Please provide the key 'priority' instead. Accepted values are: 'default', 'primary', 'secondary', 'supplemental', 'explicit'.
Warning: Found deprecated priority 'secondary' for source 'kontur' in pyproject.toml. Consider changing the priority to one of the non-deprecated values: 'default', 'primary', 'supplemental', 'explicit'.
/Users/semyonpupkov/Library/Caches/pypoetry/virtualenvs/reco-py-gv35q0vK-py3.11

I've fixed the warning, but ther error still appears.

@jfcherng
Copy link
Collaborator

That output looks good to me. All in ASCII. 🤔

@artofhuman
Copy link
Author

I added explicit path to python and that fixed this error. (because autodetection doesn't run :))

@jfcherng
Copy link
Collaborator

jfcherng commented Jan 31, 2024

That doesn't sound like something we can improve? But weirdly it worked when executed in terminal.

@artofhuman
Copy link
Author

If package can't detect python path, maybe better to use default python, or handle exception and suggest how to setup path explicitly

@rchl
Copy link
Member

rchl commented Jan 31, 2024

The package just runs poetry env info -p in a subprocess. It doesn't use any python specifically and relies on shell PATH being set correctly.

I guess in your case it just can't find poetry and the error that your shell gives in this case has some weird characters.

That said, it might still be possible to handle this error case better.

@jfcherng
Copy link
Collaborator

I guess in your case it just can't find poetry and the error that your shell gives in this case has some weird characters.

I think that would be caught by

LSP-pyright/plugin.py

Lines 250 to 251 in 4e7b80e

except FileNotFoundError:
print("{}: WARN: subprocess failed with file not found: {}".format(cls.name(), command[0]))

@rchl
Copy link
Member

rchl commented Jan 31, 2024

No, when you start subprocess with shell=True (which is the case here) it can't know what the error is in such details since it's all handled by the shell.

@rwols
Copy link
Member

rwols commented Jan 31, 2024

@artofhuman you seem to be using macOS. Sublime uses a specific file of your default shell to determine the right $PATH for that OS. See: https://lsp.sublimetext.io/troubleshooting/#updating-the-path-used-by-lsp-servers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants