1 回答

TA貢獻1864條經(jīng)驗 獲得超6個贊
我已經(jīng)弄清楚了,感謝 Lacho Tomov 在這個問題中的回答:Git push requires username and password
具有所需行為的代碼是:
import git
class User():
def __init__(self, a, b, c):
self.name = a
self.git_user = b
self.git_repos = c
user = User('John', 'john1234', 'fake_one')
try:
git.Repo.clone_from(f'https://null:null@github.com/{user.git_user}/' + \
f'{user.git_repos}.git', f'temp/{user.name}/')
except git.exc.GitError:
print(f'ERROR! {user.name}: {user.git_user}/{user.git_repos} does not exist')
請注意,nullinhttps://null:null@github.com/{user.git_user}/可能是其他一些字符串(但不是空的)。
如果有人有更pythonic/正確的方法來執(zhí)行此操作,請隨時更新此答案。
添加回答
舉報