[英]repo init UnicodeDecodeError on Ubuntu 13.04
我使用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
我的錯誤在哪里?
錯誤是指您正在使用的路徑:
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
中的0xc3 in position 9
是/home/u/Téléchargements
0xc3 in position 9
的'é'。 這似乎是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中管道輸出stdout時設置正確的編碼 )。
這個問題在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
因此,唯一可行的解決方案是將文件路徑設置為“ ascii可解碼”(無重音或非英語字符)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.