1

I use 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:

$ 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?

oHo
  • 51,447
  • 27
  • 165
  • 200

2 Answers2

6

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. This seems like a bug in repo, but you can very likely work around it by using a directory name with only ASCII characters.

In 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. 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).

Community
  • 1
  • 1
Joe
  • 29,416
  • 12
  • 68
  • 88
2

This problem is still present in 2018.

Accepted answer is fine, however I'd like to add that proposed correction (sys.getfilesystemencoding()) does not work.

To get passed the _setenv() function, we first have to decode the string with the correct encoding, in my case 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:

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:

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

jacen05
  • 36
  • 2