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

Error using Chinese path or Chinese branch name #1362

Open
xun-mi-git opened this issue Oct 19, 2021 · 2 comments
Open

Error using Chinese path or Chinese branch name #1362

xun-mi-git opened this issue Oct 19, 2021 · 2 comments

Comments

@xun-mi-git
Copy link

xun-mi-git commented Oct 19, 2021

Environmental Information

Windows10
Python3.8
GitPython 3.1.24

Error 1

Chinese path:

git.Repo.clone_from(url="git@gitee.com:xun-mi-git/test-x.git", to_path="C:\\Users\\asus\\3D Objects\\个人项目\\test")

Error message

Exception in thread Thread-6:
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 1370, in _readerthread
    buffer.append(fh.read())
UnicodeDecodeError: 'gbk' codec can't decode byte 0xaa in position 41: illegal multibyte sequence

screenshot

寻觅_20210619020652

Error 2

Chinese branch:

    git.Repo.clone_from(url="git@gitee.com:xun-mi-git/test-x.git", to_path="C:\\test")
    a = Repo("C:\\test").remotes[0]
    for i in a.refs:
        print(i.name)
    a = a.pull()

Error message

origin/HEAD
origin/默认分支
Exception in thread Thread-7:
Traceback (most recent call last):
  File "C:\Users\asus\3D Objects\Python环境\常用通用库\lib\site-packages\git\cmd.py", line 109, in pump_stream
    for line in stream:
UnicodeDecodeError: 'gbk' codec can't decode byte 0xae in position 58: illegal multibyte sequence

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2800.0_x64__qbz5n2kfra8p0\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\asus\3D Objects\Python环境\常用通用库\lib\site-packages\git\cmd.py", line 122, in pump_stream
    raise CommandError([f'<{name}-pump>'] + remove_password_if_present(cmdline), ex) from ex
git.exc.CommandError: Cmd('<stderr-pump>') failed due to: UnicodeDecodeError(''gbk' codec can't decode byte 0xae in position 58: illegal multibyte sequence')
  cmdline: <stderr-pump> git pull -v origin

screenshot

寻觅_20213119023148

@xun-mi-git
Copy link
Author

Use if required:git@gitee.com:xun-mi-git/test-x.gitThis library test

@Byron
Copy link
Member

Byron commented Oct 20, 2021

Thanks for this wonderful issue! I am sorry to say that dealing with encodings is a mess in GitPython. The examples above seem to indicate that it tries to see things as strings but doesn't get their encoding right. Probably it should just use UTF-8 instead of gbk.

Maybe as a workaround, the default encoding of the python interpreter can be set to utf-8.

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

No branches or pull requests

2 participants