Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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

Sign up
Appearance settings

I have a decode issue with GitPython#1374

AnsweredbyByron
99848873 asked this question inQ&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 sequenceThe 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 exgit.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 originUpdate 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 isgbk, but should beutf-8 for most purposes. It can be changed on startup I think.

It looks likethis is how you change the default encoding.

Replies: 2 comments 8 replies

Comment options

Byron
Nov 5, 2021
Maintainer

Strangely enough it looks like I have seen this before.

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

It looks likethis is how you change the default encoding.

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

ByronNov 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

ByronNov 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 byByron
Comment options

Some further information: On Windowsgbk refers tocode 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 byrunning the interpreter with-X utf8 or setting thePYTHONUTF8 environment variable to the value1. 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 passingencoding="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 usingencoding="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'sgit 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 bemade 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 freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
3 participants
@99848873@Byron@EliahKagan
Converted from issue

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


[8]ページ先頭

©2009-2025 Movatter.jp