GitPython - Repo.clone导致TypeError:execve()arg 2必须只包含字符串

时间:2015-02-12 22:03:41

标签: python gitpython

我正在执行以下与GitPython相关的代码,以便从远程存储库进行克隆。远程repo url的格式通常为https://username:password@host/path/to/repo.git

Repo.clone_from(repo_url, local_repo_path)

这导致以下错误,这实际上没有帮助

 File "clone.py", line 192, in clone
    Repo.clone_from(repo_url,local_repo_path)
  File "/usr/local/lib/python2.7/dist-packages/git/repo/base.py", line 844, in clone_from
    return cls._clone(Git(os.getcwd()), url, to_path, GitCmdObjectDB, progress, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/git/repo/base.py", line 791, in _clone
    v=True, **add_progress(kwargs, git, progress))
  File "/usr/local/lib/python2.7/dist-packages/git/cmd.py", line 431, in <lambda>
    return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/git/cmd.py", line 802, in _call_process
    return self.execute(make_call(), **_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/git/cmd.py", line 556, in execute
    **subprocess_kwargs
  File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
    raise child_exception
TypeError: execve() arg 2 must contain only strings

我尝试将值编码为utf-8,没有运气。在克隆命令之前记录时,这些变量的类型显示为str

Repo.clone_from(unicode(repo_url, "utf-8"), unicode(local_repo_path, "utf-8"))

2 个答案:

答案 0 :(得分:1)

我认为可能是您当前的工作目录包含unicode字符,或者os.getcwd()使用by gitpython when handling clone_from作为unicode返回。

由于最新版本的GitPython肯定会处理编码和unicode,我怀疑你没有使用最新版本的GitPython(v0.3.6)。如果你这样做,please file a bug

答案 1 :(得分:0)

我发现了什么问题。我正在解密我在将其插入repo url之前获得的密码,并且Pycrypto已经在解密密码的末尾插入了(据我所知,填充了)不可打印的字符。这是问题的根本原因。我能够在以下帮助下解决这个问题。

How can I remove non-ASCII characters but leave periods and spaces using Python?