0

Python version 3.11.3 When I use gitpython, my codes like below

os.environ["PYTHONIOENCODING"] = "utf-8"
os.environ["PYTHONUFT8"] = "on"

repo = Repo(repo_path)
remote = repo.remote()
remote.fetch()

if there is a branch named with Chinese like "测试分支", it will throw error

git.exc.CommandError: Cmd('<stderr-pump>') failed due to: UnicodeDecodeError(''gbk' codec can't decode byte 0xad in position 54: illegal multibyte sequence')

I know it's an encoding problem, I've already set PYTHONUTF8=1 and PYTHONIOENCODING='utf-8',but it doesn't work.

  1. Does fetch method have any params like encoding='utf-8'?
  2. How could I use fetch with utf-8?
  3. Why does it auto choose gbk?

1 Answer 1

0

Tried newest Gitpython, fetch doesn't throw the error no more. However, remote().fetch().name and other parts remain GBK encoding.

So far from what I can try, the best to walk around this is to: str(bytes(remote().fetch().name,'gbk'), encoding='utf-8')

Update: Suppose this error only happens in Windows. In order to make GitPython not to use gbk as default codec, you can change Windows settings: inside Time and languages -> Languages and areas -> Manage language settings -> Management tab -> None Unicode programme and language -> Change -> Check Beta: Use Unicode UTF-8 to support global language support and restart. Which should work afterwards.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.