第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

想檢查存儲庫是否存在以及它是否是公共的(gitpython)

想檢查存儲庫是否存在以及它是否是公共的(gitpython)

使用 Python 和 GitPython,以及來自不同用戶的 git 存儲庫列表,我需要檢查存儲庫是否存在以及它是否是公共的??紤]到這一點并考慮 GitHub,如果它要求輸入用戶名和密碼,我知道該存儲庫超出了我的標準。因此,我可以忽略它。import gitclass User():    def __init__(self, a, b, c):        self.name = a        self.git_user = b        self.git_repos = cuser = User('John', 'john1234', 'fake_one')try:    git.Repo.clone_from(f'https://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')此代碼有效,到目前為止,當未找到存儲庫為公共存儲庫時,我使用任何用戶名和相應(yīng)密碼(包括空密碼)輸入。有沒有辦法忽略(通過發(fā)送空字符串)或捕獲(某些例外?)用戶名/密碼的東西?請注意,如果我可以檢查(公共)存儲庫是否存在,我可以使用此信息來防止不適當?shù)摹翱寺 ?..
查看完整描述

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í)行此操作,請隨時更新此答案。


查看完整回答
反對 回復(fù) 2021-12-16
  • 1 回答
  • 0 關(guān)注
  • 184 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號