git-repo
git-repo copied to clipboard
GitError: config: environment can only contain strings
I was using repo init: repo init -u git://github.com/MiCode/patchrom.git -b marshmallow then i got
Traceback (most recent call last): File "C:\Users\admin.repo\repo\git_command.py", line 311, in init p = subprocess.Popen(command, File "C:\Users\admin\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 854, in init self._execute_child(args, executable, preexec_fn, close_fds, File "C:\Users\admin\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1307, in _execute_child hp, ht, pid, tid = _winapi.CreateProcess(executable, args, TypeError: environment can only contain strings
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\admin.repo\repo/main.py", line 568, in
How do I fix this??
Same issue. Waiting for the answer.
UPDATE: Caused by windows encoding.
Found an alternative solution, inspired by this post
Add the code below to __init__
function inside git_command.py
try:
# ADD START: clean the encoding
env_clean = {}
for k in env:
key = k
if isinstance(key, unicode):
key = key.encode('utf-8')
env_clean[key] = env[k]
if isinstance(env_clean[key], unicode):
env_clean[key] = env_clean[key].encode('utf-8')
env = env_clean
# ADD END
p = subprocess.Popen(command,
cwd=cwd,
env=env,
stdin=stdin,
stdout=stdout,
stderr=stderr)
Above solution is not working for me on windows with python 3.8 version. Observing the same failure (modified unicode to str in above snippet to make it work for py3)
Any other solutions are appreciated. Thanks
I think on Windows, somehow the env is stored as utf-8 encoded bytes/bytearray. But it only accept string in the env Popen( env…)
So instead of encoding, we need decoding bytes to str I modified above solution as following. Then it works on Windows py3
# ADD START: clean the encoding
env_clean = {}
for k, v in env.items():
if isinstance(k, bytes):
k = k.decode('utf-8')
if isinstance(v, bytes):
v = v.decode('utf-8')
env_clean[k] = v
env = env_clean
# ADD END