2

如何使用 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 库中实现它?

4

2 回答 2

4

以下两种方法已经用 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',
)
于 2016-09-07T06:54:50.833 回答
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')
于 2015-07-23T14:24:12.780 回答