Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git clone using GitPython library

Tags:

ssl

gitpython

How to clone with disabled SSL checking, using GitPython library. The following code ...

import git
x = git.Repo.clone_from('https://xxx', '/home/xxx/lala')

... yields this error:

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

I know about "export GIT_SSL_NO_VERIFY=1", but how to implement it in a python library ?

like image 723
Petr Avatar asked Jul 02 '26 19:07

Petr


2 Answers

The two following methods have been tested with GitPython 2.0.8 but should be working at least since 1.0.2 (from the doc).

As suggested by @Byron:

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

As suggested by @Christopher:

git.Repo.clone_from(
  'https://example.net/path/to/repo.git',
  'local_destination',
  branch='master', depth=1,
  config='http.sslVerify=false',
)
like image 121
bufh Avatar answered Jul 04 '26 11:07

bufh


It seems easiest to pass the GIT_SSL_NO_VERIFY environment variable to all git invocations. Unfortunately Git.update_environment(...) can only be used on an existing instance, which is why you would have to manipulate python's environment like so:

import git
import os

os.environ['GIT_SSL_NO_VERIFY'] = "1"
repo = git.Repo.clone_from('https://xxx', '/home/xxx/lala')
like image 44
Byron Avatar answered Jul 04 '26 11:07

Byron



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!