Skip to content

Error using Chinese path or Chinese branch name #1362

Open
@xunmi-git

Description

@xunmi-git

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

Activity

xunmi-git

xunmi-git commented on Oct 19, 2021

@xunmi-git
Author

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

Byron

Byron commented on Oct 20, 2021

@Byron
Member

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @Byron@xunmi-git

        Issue actions

          Error using Chinese path or Chinese branch name · Issue #1362 · gitpython-developers/GitPython