简体   繁体   中英

Clone from a Gitlab community private repo using a private token in Python script

I'd like to be able to clone a private git repository hosted on a Gitlab community edition providing my private token. I tried using gitpython library and i can do the following :

from os.path import abspath
from git import Repo
to_path = abspath("C:\mypath\test")
Repo.clone_from("http://gitlab-ci-token:my_CI_token@myurl/testgroup/test.git", to_path)

This is working and clones the repo nicely. The problem is that I want to use my private token and not the CI token of the repository. And this is not working :

Repo.clone_from("http://my_login:my_private_token@myurl/testgroup/test.git", to_path)

I even tried to use my password but couldn't get it to work neither.

If i want to use my private token it's because my script tries to clone all the repositories stored in a Gitalb group (here testgroup) and I don't know beforehand repositories that will be there so I can't get their CI token in the script.

I'll take any solution that let me clone a repository with a Login/private_token or a login/password without interactive authentication.

I'm not sure what you mean by:

I even tried to use my password but couldn't get it to work neither.

Setting your username and password in the URL should work:

Repo.clone_from("https://myself%40example.net:password@gitlab.example.com/username/repo.git", to_path)

Also, instead of having passwords stored in your source code, you should consider cloning your repos using SSH, or using the credential helper system.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM