1 回答

TA贡献1864条经验 获得超6个赞
我已经弄清楚了,感谢 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/正确的方法来执行此操作,请随时更新此答案。
添加回答
举报