如何在python腳本中將密碼添加到git clone url?

拉斯克拉特船長

我在試圖從 bitbucket 中拉下一個 repo 的 python lambda 中有這個小代碼:

import git

def git_clone(username,password):
   new_dir = os.getcwd() + "/temp/"
   os.chdir(new_dir)

   GIT_URL = "https://{0}:{1}@bitbucket.org/test-project/test.git".format(username,password)

   git.Git(new_dir).clone(GIT_URL)

git 方法接受我的用戶名但不接受我的密碼。我的密碼包含字母、數字和特殊字符。我收到這個錯誤:

URL using bad/illegal format or missing URL

這可能是格式問題嗎?

凱文·穆庫納

如果使用 bitbucket,請參閱文檔

git clone "https://x-token-auth:{token}@bitbucket.org/<user_name>/"

或者

url = r"https://x-token-auth:{token}@bitbucket.org/<user_name>/"

git克隆網址

這是您的問題的解決方案。我測試了它並且它有效。

#!/usr/bin/env python
import os 

def git_clone(password, username):
    if password and username:
        url_string = r"git clone https://{}:{}@bitbucket.org/{}/test.git".format(username, password, username)
        os.system(url_string)
git_clone(username="<username>", password="<password>")

如果這解決了您的問題,請不要忘記接受並將其作為正確答案

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章