简体   繁体   English

在Ubuntu 13.04上回购init UnicodeDecodeError

[英]repo init UnicodeDecodeError on Ubuntu 13.04

I use repo-1.19 : 我使用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]

But when I try to initialize it I have the Python UnicodeDecodeError: 但是当我尝试对其进行初始化时,我遇到了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)

I have followed advices from: 我遵循以下建议:

I have tried many many possibilities, but no success: 我尝试了很多可能性,但没有成功:

./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

Where is my mistake? 我的错误在哪里?

The error is referring to the path you're using: 错误是指您正在使用的路径:

  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 is the 'é' of /home/u/Téléchargements . 0xc3 in position 9中的0xc3 in position 9/home/u/Téléchargements 0xc3 in position 9的'é'。 This seems like a bug in repo , but you can very likely work around it by using a directory name with only ASCII characters. 这似乎是repo的错误,但是您很可能可以通过使用仅包含ASCII字符的目录名称来解决此问题。

In git_command.py : git_command.py

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

With Python 2, this tries to encode the value as US-ASCII, which fails. 使用Python 2,这会尝试将值编码为US-ASCII,这会失败。 It should possibly be: 它可能应该是:

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

(see also Setting the correct encoding when piping stdout in Python ). (另请参阅在Python中管道输出stdout时设置正确的编码 )。

This problem is still present in 2018. 这个问题在2018年仍然存在。

Accepted answer is fine, however I'd like to add that proposed correction (sys.getfilesystemencoding()) does not work. 接受的答案很好,但是我想补充一点,建议的更正(sys.getfilesystemencoding())不起作用。

To get passed the _setenv() function, we first have to decode the string with the correct encoding, in my case UTF-8: 为了通过_setenv()函数,我们首先必须使用正确的编码对字符串进行解码,在我的情况下为UTF-8:

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

But then we are stuck with other errors. 但是后来我们陷入了其他错误。 If we just decode it as mentionned, some other blocks of code will treat it as ascii and try to decode it as such, thus throwing the same kind of error: 如果我们只是如上所述解码它,那么其他一些代码块会将其视为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)

If we try to encode it in ascii, either by ignoring the error, or replacing the error characters, the encoding will "work" but the filepath will be erroneous thus leading to another error: 如果我们尝试通过忽略错误或替换错误字符以ascii对其进行编码,则编码将“起作用”,但文件路径将错误,从而导致另一个错误:

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

Thus only working solution is to make your file path "ascii-decodable" (no accent or non-English characters). 因此,唯一可行的解​​决方案是将文件路径设置为“ ascii可解码”(无重音或非英语字符)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM