Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

I have a decode issue with GitPython #1374

Answered by Byron
99848873 asked this question in Q&A
Discussion options

My code is ,

image

And there is no chinese in my repo path。

And an exception was found.

Exception in thread Thread-22:
Traceback (most recent call last):
  File "C:\zhoujinyuWorkSpace\MyUe4\pyscript\venv\lib\site-packages\git\cmd.py", line 106, in pump_stream
    for line in stream:
UnicodeDecodeError: 'gbk' codec can't decode byte 0xa8 in position 1297: illegal multibyte sequence

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

Traceback (most recent call last):
  File "c:\python38\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "c:\python38\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "C:\zhoujinyuWorkSpace\MyUe4\pyscript\venv\lib\site-packages\git\cmd.py", line 119, 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 0xa8 in position 1297: illegal multibyte sequence')
  cmdline: <stderr-pump> git pull -v origin
Update C:/workspace/AClient_Bin/AClient/Content/ repo
You must be logged in to vote

Strangely enough it looks like I have seen this before.

The problem seems to be that the python interpreter default code is gbk, but should be utf-8 for most purposes. It can be changed on startup I think.

It looks like this is how you change the default encoding.

Replies: 2 comments · 8 replies

Comment options

Strangely enough it looks like I have seen this before.

The problem seems to be that the python interpreter default code is gbk, but should be utf-8 for most purposes. It can be changed on startup I think.

It looks like this is how you change the default encoding.

You must be logged in to vote
8 replies
@Byron
Comment options

Byron Nov 5, 2021
Maintainer

Screen Shot 2021-11-05 at 3 07 48 PM

What about setting the IO encoding?

@99848873
Comment options

I had tried other function.
image
Got another failed
Cmd('git') failed due to: exit code(1)
cmdline: git pull -v Develop

@99848873
Comment options

All are utf-8
image

@99848873
Comment options

I tried repo.git.pull() and without any parameters,it was wroking.
image

@Byron
Comment options

Byron Nov 6, 2021
Maintainer

Where is the 'gbk' codec coming from? Is it some other program code outside of GitPython that sets it? What are these values after executing the code running GitPython?

Answer selected by Byron
Comment options

Some further information: On Windows gbk refers to code page 936, and it is the default ANSI active code page on Windows in some locales, especially where Chinese is spoken. Where English is spoken, code page 1252 is most often the default in Windows.

Python can be made to use UTF-8 instead of the ANSI active code page by running the interpreter with -X utf8 or setting the PYTHONUTF8 environment variable to the value 1. I have found that this (the -X way) has been sufficient to overcome some limitations, such as #1747 before it was fixed. I am unsure if it is sufficient to overcome all such limitations; I have not at this point tested to see if it ameliorates #1362.

Python will also use UTF-8 when instructed to do so, by passing encoding="utf-8" where applicable, which is something that has to be done in the code of a program. If running Python with -X utf8 is sufficient to work around most or all encoding limitations in GitPython, then it might be possible to fix them by using encoding="utf-8" in most or all calls to functions that recognize it (when operating with text). But I am unsure if that would work, because there is also the behavior of external programs, particularly GitPython's git subprocesses, to consider.

Unlike other systems where the most closely related locale settings are more readily changed and can be changed easily for specific commands using simple and well-documented techniques, the ANSI active code page on a Windows system is a system-level setting (unlike the interface language setting and preferred language settings), which can be changed, but only for the whole system, and this is rarely done. This post and its linked sources provide some more information about that. Windows can also be made to use UTF-8 where it would otherwise use a localized code page, though this is considered "beta" and some applications might have problems.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #1373 on November 05, 2021 06:51.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.