使用GitPython库进行git clone

3
如何使用GitPython库进行禁用SSL检查的克隆。以下代码...
import git
x = git.Repo.clone_from('https://xxx', '/home/xxx/lala')

这样会出现以下错误:

Error: fatal: unable to access 'xxx': server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none

我知道 "export GIT_SSL_NO_VERIFY=1",但如何在Python库中实现它?
2个回答

6

以下两种方法已经在 GitPython 2.0.8 上进行了测试,但应该至少可以在 1.0.2 上使用(来自文档)。

如 @Byron 所建议:

git.Repo.clone_from(
  'https://example.net/path/to/repo.git',
  'local_destination',
  branch='master', depth=1,
  env={'GIT_SSL_NO_VERIFY': '1'},
)

根据@Christopher的建议:

git.Repo.clone_from(
  'https://example.net/path/to/repo.git',
  'local_destination',
  branch='master', depth=1,
  config='http.sslVerify=false',
)

1

似乎最简单的方法是将GIT_SSL_NO_VERIFY环境变量传递给所有git调用。不幸的是,Git.update_environment(...)只能用于现有实例,这就是为什么您需要像下面这样操作python环境:

import git
import os

os.environ['GIT_SSL_NO_VERIFY'] = "1"
repo = git.Repo.clone_from('https://xxx', '/home/xxx/lala')

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接