1

我使用repo-1.19

$ wget -nv 'http://code.google.com/p/git-repo/downloads/detail?name=repo-1.19'
2013-08-05 02:36:32 URL:http://code.google.com/p/git-repo/downloads/detail?name=repo-1.19 [9673] -> "detail?name=repo-1.19.3" [1]
$ chmod +x repo-1.19 
$ ./repo-1.19 --version
repo version v1.12.2
       (from https://gerrit.googlesource.com/git-repo)
repo launcher version 1.19
       (from /home/u/Téléchargements/repo-1.19)
git version 1.8.1.2
Python 2.7.4 (default, Jul  5 2013, 08:21:57) 
[GCC 4.7.3]

但是当我尝试初始化它时,我遇到了 Python UnicodeDecodeError:

$ rm -rf .repo
$ ./repo-1.19 init -u git://github.com/CyanogenMod/android.git -b cm-10.2
Get https://gerrit.googlesource.com/git-repo
remote: Counting objects: 101, done
remote: Finding sources: 100% (101/101)
remote: Total 2533 (delta 1442), reused 2533 (delta 1442)
Receiving objects: 100% (2533/2533), 1.71 MiB | 1.80 MiB/s, done.
Resolving deltas: 100% (1442/1442), done.
From https://gerrit.googlesource.com/git-repo
 * [new branch]      maint      -> origin/maint
 * [new branch]      master     -> origin/master
 * [new branch]      stable     -> origin/stable
 * [new tag]         v1.0       -> v1.0
 [... lines removed ...]
 * [new tag]         v1.9.6     -> v1.9.6
Get git://github.com/CyanogenMod/android.git
Traceback (most recent call last):
  File "/home/u/Téléchargements/.repo/repo/main.py", line 414, in <module>
    _Main(sys.argv[1:])
  File "/home/u/Téléchargements/.repo/repo/main.py", line 390, in _Main
    result = repo._Run(argv) or 0
  File "/home/u/Téléchargements/.repo/repo/main.py", line 138, in _Run
    result = cmd.Execute(copts, cargs)
  File "/home/u/Téléchargements/.repo/repo/subcmds/init.py", line 347, in Execute
    self._SyncManifest(opt)
  File "/home/u/Téléchargements/.repo/repo/subcmds/init.py", line 137, in _SyncManifest
    m._InitGitDir()
  File "/home/u/Téléchargements/.repo/repo/project.py", line 1847, in _InitGitDir
    self.bare_git.init()
  File "/home/u/Téléchargements/.repo/repo/project.py", line 2197, in runner
    capture_stderr = True)
  File "/home/u/Téléchargements/.repo/repo/git_command.py", line 167, in __init__
    _setenv(env, GIT_DIR, gitdir)
  File "/home/u/Téléchargements/.repo/repo/git_command.py", line 120, in _setenv
    env[name] = value.encode()
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 9: ordinal not in range(128)

我遵循了以下建议:

我尝试了很多可能性,但没有成功:

./repo-1.19 init -u   git://android.git.kernel.org/platform/manifest.git -b android-4.3_r2
./repo-1.19 init -u https://android.git.kernel.org/platform/manifest.git -b android-4.3_r2
./repo-1.19 init -u git://android.googlesource.com/platform/manifest

我的错误在哪里?

4

2 回答 2

6

该错误是指您正在使用的路径:

  File "/home/u/Téléchargements/.repo/repo/git_command.py", line 120, in _setenv
    env[name] = value.encode()
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 9: ordinal not in range(128)

0xc3 in position 9是 的 'é' /home/u/Téléchargements。这似乎是 中的一个错误repo,但您很可能通过使用仅包含 ASCII 字符的目录名称来解决它。

git_command.py

def _setenv(env, name, value):
  env[name] = value.encode()

在 Python 2 中,这会尝试将值编码为 US-ASCII,但失败了。应该是:

def _setenv(env, name, value):
  env[name] = value.encode(sys.getfilesystemencoding())

(另请参阅在 Python 中管道标准输出时设置正确的编码)。

于 2013-08-05T11:49:28.440 回答
2

这个问题在 2018 年仍然存在。

接受的答案很好,但是我想补充一点,建议的更正 (sys.getfilesystemencoding()) 不起作用。

要通过_setenv()函数,我们首先必须使用正确的编码解码字符串,在我的例子中是 UTF-8:

env[name] = value.decode('UTF-8')

但是后来我们遇到了其他错误。如果我们只是按照提到的方式对其进行解码,其他一些代码块会将其视为 ascii 并尝试对其进行解码,从而引发相同类型的错误:

File "/path/to/repo/.repo/repo/git_command.py", line 238, in __init__
raise GitError('%s: %s' % (command[1], e))
error.GitError: init: 'ascii' codec can't encode character u'\xe9' in position 14: ordinal not in range(128)

如果我们尝试在 ascii 中对其进行编码,或者忽略错误,或者替换错误字符,编码将“起作用”,但文件路径将是错误的,从而导致另一个错误:

error.GitError: manifests init: fatal: Could not switch to '/path/to/rpo/.repo/': No such file or directory

因此,唯一可行的解​​决方案是使您的文件路径“可解码”(无重音或非英文字符)。

于 2018-07-18T19:45:52.997 回答