Skip to content
This repository has been archived by the owner on Jul 27, 2018. It is now read-only.

Error when I wrote Chinese character in python file #148

Closed
xrayw opened this issue Oct 18, 2017 · 16 comments
Closed

Error when I wrote Chinese character in python file #148

xrayw opened this issue Oct 18, 2017 · 16 comments

Comments

@xrayw
Copy link

xrayw commented Oct 18, 2017

  • platform: windows10
  • vim version: vim 8.596
  • and with both newest nvim-completion-manager and vim-hug-neovim-rpc .

It is 100% appear on my machine.
Have you ever had the same situation?

@roxma
Copy link
Owner

roxma commented Oct 18, 2017

What error?

Could you post more informaton, including the reproducing steps.

I don't have a Windows currently, and I cannot reproduce it on my vim8.

@xrayw
Copy link
Author

xrayw commented Oct 18, 2017

@roxma
Thanks for your reply.

To reproduce this bug:

  1. A new python file.
  2. Write a Chinese character, and i got it.

en. There are more information in log file, and I can't catch the point.
Or I send the log file to your email?

@roxma
Copy link
Owner

roxma commented Oct 18, 2017

Use gist or paste bin for pasting log file.

@xrayw
Copy link
Author

xrayw commented Oct 18, 2017

Like this log ?

@roxma
Copy link
Owner

roxma commented Oct 18, 2017

What's the error shown on the screen?

I also need the result of set encoding and set fileencoding after you openning the buffer

And a minimal vimrc for reproducing the error.

@roxma
Copy link
Owner

roxma commented Oct 18, 2017

I can reproduce the error on my laptop with set encoding=cp936

screenshot_20171018_174134

vimrc:

    set nocompatible
    syntax on
    filetype plugin indent on
    set encoding=utf-8 fileencodings=ucs-bom,utf-8,gbk,gb18030,latin1 termencoding=utf-8

    call plug#begin(expand('<sfile>:h') . '/plugged/')
    Plug 'roxma/nvim-completion-manager'
        if !has('nvim')
            Plug 'roxma/vim-hug-neovim-rpc'
        endif
    call plug#end()
    set encoding=cp936

It's working fine with set encoding=utf-8

@xrayw
Copy link
Author

xrayw commented Oct 18, 2017

  • encoding=utf-8
  • fileencoding=utf-8

The screen:
1
\
2

vimrc:

    set nocompatible
    set encoding=utf-8

    set fileencoding=utf-8
    set fileencodings=utf8,cp936,ucs-bom,latin1,chinese

    call plug#begin('$VIM/vimfiles/plugged')
    Plug 'roxma/nvim-completion-manager'
    if !has('nvim')
        Plug 'roxma/vim-hug-neovim-rpc'
    endif
    call plug#end()

But I can't reproduce the error with the mini vimrc. It seems other setting caused it, I'll check my configuration, And test it on mac.

thanks for your help.

@roxma
Copy link
Owner

roxma commented Oct 18, 2017

It's wierd that python is executing code in encodings\cp1252.py

@roxma
Copy link
Owner

roxma commented Oct 18, 2017

What's the result of

  • :python3 print(sys.getdefaultencoding())
  • :python3 print(sys.getfilesystemencoding())
  • :python3 import locale; print(locale.getpreferredencoding())

@roxma
Copy link
Owner

roxma commented Oct 18, 2017

Interesting:

>>> "\u5f00"
'开'
>>> "\u5f00".encode('cp1252')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/rh/rh-python35/root/usr/lib64/python3.5/encodings/cp1252.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_table)
UnicodeEncodeError: 'charmap' codec can't encode character '\u5f00' in position 0: character maps to <undefined>
>>> "\u5f00".encode('cp936')
b'\xbf\xaa'
>>>
>>> "\u86e4"
'蛤'
>>> "\u86e4".encode('cp1252')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/rh/rh-python35/root/usr/lib64/python3.5/encodings/cp1252.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_table)
UnicodeEncodeError: 'charmap' codec can't encode character '\u86e4' in position 0: character maps to <undefined>

@roxma
Copy link
Owner

roxma commented Oct 18, 2017

My guess: Replacing your python installation with python 3.6 or higher will fix this issue.

@xrayw
Copy link
Author

xrayw commented Oct 19, 2017

  • :python3 print(sys.getdefaultencoding()) => utf-8
  • :python3 print(sys.getfilesystemencoding()) => mbcs
  • :python3 import locale; print(locale.getpreferredencoding()) => cp1252

It works fine on Mac.

@roxma
Copy link
Owner

roxma commented Oct 19, 2017

The screenshot you posted is triggered by logging.

What does it look like without enabling logging?

@xrayw
Copy link
Author

xrayw commented Oct 20, 2017

Oh, I can't reproduce the bug now.

@xrayw
Copy link
Author

xrayw commented Oct 24, 2017

It seems caused by logging,
When I re-enable the logging configuration of NCM, It repeared again.

And shown logging error :

@roxma
Copy link
Owner

roxma commented Oct 24, 2017

Ok. Update vim-hug-neovim-rpc to the latest version.

And let's wait for the next release of neovim python client. // neovim/pynvim#276

// cc @justinmk

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

No branches or pull requests

2 participants