neovim / pynvim

Python client and plugin host for Nvim
http://pynvim.readthedocs.io/en/latest/
Apache License 2.0
1.48k stars 118 forks source link

UnicodeDecodeError: 'gbk' codec can't decode byte 0xa6 in position 18260: illegal #443

Closed WingDust closed 3 years ago

WingDust commented 4 years ago

neoclide/coc.nvim#1828 Before i through is Coc.nvim problem but now look like it's vim-snippets

Describe the bug

OS : window10 Neovim: 0.4.3 i check again the CocInfo it't return different message

CocInfo


Output channel: Python

Starting Jedi Python language engine.

Output channel: snippets

[Info 17:39:57] Using ultisnips directories: UltiSnips E:\spacemacs\emacs26-3\AppData\Local\coc\ultisnips [Info 17:39:58] Using ultisnips python command: pyx Error on execute python script: request error nvim_command - Vim(return):Error invoking 'python_execute_file' on channel 4 (python3-script-host): error caught in request handler 'python_execute_file ['C:\Users\ADMINI~1\AppData\Local\Temp\coc.nvim-6652\coc-ultisnips-KLQQlwM_rh.py', 1, 1]': Traceback (most recent call last): File "E:\python\python3.8.1\lib\site-packages\pynvim\plugin\script_host.py", line 106, in python_execute_file script = compile(f.read(), file_path, 'exec') UnicodeDecodeError: 'gbk' codec can't decode byte 0xa6 in position 18260: illegal multibyte sequence


init.vim


  Plug 'neoclide/coc.nvim',{'branch':'release'}

  inoremap <silent><expr> <TAB>
        \ pumvisible() ? "\<C-n>" :
        \ <SID>check_back_space() ? "\<TAB>" :
        \ coc#refresh()
  inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"

  " Snippet
  " Plug 'SirVer/ultisnips'
  Plug 'honza/vim-snippets'

Try

I thought it's cmd default encoding problem so change to utf-8 but don't work

justinmk commented 4 years ago

what python version? see https://github.com/neovim/pynvim/pull/439 (merged but not released)

WingDust commented 4 years ago

python :3.8.1

justinmk commented 4 years ago

actually why is "gbk" encoding involved? Only utf8 is supported.

Shougo commented 4 years ago

It seems binary file decoding error.

    @rpc_export('python_execute_file', sync=True)
    def python_execute_file(self, file_path, range_start, range_stop):
        """Handle the `pyfile` ex command."""
        self._set_current_range(range_start, range_stop)
        with open(file_path) as f:
            script = compile(f.read(), file_path, 'exec')
            try:
                exec(script, self.module.__dict__)
            except Exception:
                raise ErrorResponse(format_exc_skip(1))

open() opens file as text file. But your opened file is invalid text(binary) file. f.read() decodes byte as gbk codecs (system default encoding??), but it failed.

Shougo commented 4 years ago

It is not #439 related problem. I think open() should use encoding argument to detect encoding.

justinmk commented 4 years ago

I think open() should use encoding argument to detect encoding.

maybe we can show a better error. But supporting non-utf8 file for python_execute_file does not seem like something we should do.

Shougo commented 4 years ago

maybe we can show a better error. But supporting non-utf8 file for python_execute_file does not seem like something we should do.

If so, open(encoding='utf-8') should be used instead. And to add the documentation.

Note: I don't know what pyfile supports encodings in Vim8.

ghost commented 3 years ago

Is there a solution to this problem

Describe the bug

fcying commented 3 years ago

modify python_path\Lib\site-packages\pynvim\plugin\script_host.py +107 can work.

with open(file_path, 'rb') as f:        #with open(file_path) as f: 
Shougo commented 3 years ago

@bfredl Ping.

Shougo commented 3 years ago

465 is merged. So it can be closed.

gera2ld commented 3 years ago

When will the fix be released? The issue still exists in the latest release.

Shougo commented 3 years ago

@bfredl Ping. When the new version is released? This is very important problem for me.

Shougo commented 3 years ago

version 0.4.3 is released. It should be closed.

Shougo commented 3 years ago

Thanks.